Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- Thread = class(TThread)
- public
- procedure Execute; Override;
- end;
- procedure Send;
- Var
- Th: Thread;
- Begin
- Th := Thread.Create(True);
- Th.FreeOnTerminate := True;
- Th.Resume;
- End;
- procedure Thread_.Execute;
- var
- IdSMTP: TIdSMTP;
- Email: TIdMessage;
- SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
- begin
- IdSMTP := TIdSMTP.Create(nil);
- SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
- Email := TIdMessage.Create(nil);
- try
- SSLHandler.MaxLineAction := maException;
- SSLHandler.SSLOptions.Method := sslvSSLv23;
- SSLHandler.SSLOptions.Mode := sslmUnassigned;
- SSLHandler.SSLOptions.VerifyMode := [];
- SSLHandler.SSLOptions.VerifyDepth := 0;
- IdSMTP.IOHandler := SSLHandler;
- for I := 0 to Form1.MemoEmails.Lines.Count - 1 do
- begin
- IdSMTP.Host := 'smtp.live.com';
- IdSMTP.Port := Porta;
- IdSMTP.Username := Usu;
- IdSMTP.Password := Pass;
- IdSMTP.UseTLS := utUseExplicitTLS;
- Email.Clear;
- Email.From.Address := 'myuser@hotmail.com';
- Email.From.Name := 'Foo name';
- Email.Recipients.EmailAddresses := Form1.MemoEmails.Lines.Strings[I];;
- Email.Subject := 'Subject';
- Email.Body.Text := '<b>This is a test email</b>';
- Email.ContentType := 'text/html';
- Email.CharSet := 'utf-8';
- try
- if (not IdSMTP.Connected) then
- begin
- IdSMTP.Connect;
- IdSMTP.Authenticate;
- ShowMessage(EmailAtual);
- end;
- except
- on E: Exception do
- begin
- MessageDlg('Erro na conexão ou autenticação: ' + E.Message,
- mtWarning, [mbOK], 0);
- exit;
- end;
- end;
- try
- if IdSMTP.Connected then
- begin
- IdSMTP.Send(Email);
- MessageDlg('Mensagem enviada com sucesso!', mtInformation, [mbOK], 0);
- end;
- except
- On E: Exception do
- begin
- MessageDlg('Erro ao enviar a mensagem: ' + E.Message, mtWarning, [mbOK], 0);
- end;
- end;
- end;
- finally
- Email.Free;
- SSLHandler.Free;
- IdSMTP.Free;
- IdSMTP.Disconnect;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement