Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. type
  2. Thread = class(TThread)
  3. public
  4. procedure Execute; Override;
  5. end;
  6.  
  7. procedure Send;
  8. Var
  9. Th: Thread;
  10. Begin
  11. Th := Thread.Create(True);
  12. Th.FreeOnTerminate := True;
  13. Th.Resume;
  14. End;
  15.  
  16. procedure Thread_.Execute;
  17. var
  18. IdSMTP: TIdSMTP;
  19. Email: TIdMessage;
  20. SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
  21. begin
  22. IdSMTP := TIdSMTP.Create(nil);
  23. SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  24. Email := TIdMessage.Create(nil);
  25.  
  26. try
  27. SSLHandler.MaxLineAction := maException;
  28. SSLHandler.SSLOptions.Method := sslvSSLv23;
  29. SSLHandler.SSLOptions.Mode := sslmUnassigned;
  30. SSLHandler.SSLOptions.VerifyMode := [];
  31. SSLHandler.SSLOptions.VerifyDepth := 0;
  32.  
  33. IdSMTP.IOHandler := SSLHandler;
  34.  
  35. for I := 0 to Form1.MemoEmails.Lines.Count - 1 do
  36. begin
  37.  
  38. IdSMTP.Host := 'smtp.live.com';
  39. IdSMTP.Port := Porta;
  40. IdSMTP.Username := Usu;
  41. IdSMTP.Password := Pass;
  42. IdSMTP.UseTLS := utUseExplicitTLS;
  43.  
  44. Email.Clear;
  45. Email.From.Address := 'myuser@hotmail.com';
  46. Email.From.Name := 'Foo name';
  47. Email.Recipients.EmailAddresses := Form1.MemoEmails.Lines.Strings[I];;
  48. Email.Subject := 'Subject';
  49. Email.Body.Text := '<b>This is a test email</b>';
  50. Email.ContentType := 'text/html';
  51. Email.CharSet := 'utf-8';
  52.  
  53. try
  54. if (not IdSMTP.Connected) then
  55. begin
  56. IdSMTP.Connect;
  57. IdSMTP.Authenticate;
  58. ShowMessage(EmailAtual);
  59. end;
  60. except
  61. on E: Exception do
  62. begin
  63. MessageDlg('Erro na conexão ou autenticação: ' + E.Message,
  64. mtWarning, [mbOK], 0);
  65. exit;
  66. end;
  67. end;
  68.  
  69. try
  70. if IdSMTP.Connected then
  71. begin
  72. IdSMTP.Send(Email);
  73. MessageDlg('Mensagem enviada com sucesso!', mtInformation, [mbOK], 0);
  74. end;
  75. except
  76. On E: Exception do
  77. begin
  78. MessageDlg('Erro ao enviar a mensagem: ' + E.Message, mtWarning, [mbOK], 0);
  79. end;
  80. end;
  81. end;
  82. finally
  83. Email.Free;
  84. SSLHandler.Free;
  85. IdSMTP.Free;
  86. IdSMTP.Disconnect;
  87. end;
  88. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement