EmailSender.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 23932: EmailSender.pas
  11. {
  12. { Rev 1.1 01/10/2003 22:30:50 CCostelloe
  13. { Minor chane
  14. }
  15. {
  16. { Rev 1.0 26/09/2003 00:04:06 CCostelloe
  17. { Initial
  18. }
  19. unit EmailSender;
  20. interface
  21. {$I IdCompilerDefines.inc}
  22. uses
  23. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  24. Dialogs, StdCtrls, Buttons,
  25. {$IFDEF INDY100}
  26. IdSASLList, IdUserPassProvider, IdSASLLogin,
  27. {$ENDIF}
  28. IdSMTP
  29. ;
  30. type
  31. TSendEmail = class(TForm)
  32. BitBtn1: TBitBtn;
  33. BitBtn2: TBitBtn;
  34. Label1: TLabel;
  35. CheckBox1: TCheckBox;
  36. Label2: TLabel;
  37. Label3: TLabel;
  38. Label4: TLabel;
  39. Label5: TLabel;
  40. Label6: TLabel;
  41. Label7: TLabel;
  42. Label8: TLabel;
  43. Edit1: TEdit;
  44. Edit2: TEdit;
  45. Edit3: TEdit;
  46. Edit4: TEdit;
  47. Edit5: TEdit;
  48. Edit6: TEdit;
  49. procedure BitBtn1Click(Sender: TObject);
  50. procedure FormActivate(Sender: TObject);
  51. private
  52. { Private declarations }
  53. {$IFDEF INDY100}
  54. {This uses a different login system, need extra components (at least for SMTP)...}
  55. TheSASLList : TIdSASLList;
  56. ThePassProvider : TIdUserPassProvider;
  57. TheSASLLogin : TIdSASLLogin;
  58. {$ENDIF}
  59. TheSmtp : TIdSMTP;
  60. public
  61. { Public declarations }
  62. end;
  63. var
  64. SendEmail: TSendEmail;
  65. implementation
  66. uses EncoderPlayground;
  67. {$R *.dfm}
  68. procedure TSendEmail.BitBtn1Click(Sender: TObject);
  69. var
  70. TheParams: TStringList;
  71. begin
  72. //Send the email...
  73. if CheckBox1.Checked = True then begin
  74. //Save the settings...
  75. TheParams:= TStringList.Create;
  76. TheParams.Add('SmtpServer='+Edit1.Text);
  77. TheParams.Add('SmtpUsername='+Edit2.Text);
  78. TheParams.Add('SmtpPassword='+Edit3.Text);
  79. TheParams.Add('SmtpTo='+Edit4.Text);
  80. TheParams.Add('SmtpFrom='+Edit5.Text);
  81. TheParams.Add('SmtpSubject='+Edit6.Text);
  82. TheParams.SaveToFile('C:\IndyEncoderSmtp.dat');
  83. TheParams.Destroy;
  84. end;
  85. TheSmtp := TIdSMTP.Create(nil);
  86. {$IFDEF INDY100}
  87. {This uses a different login system, need extra components (at least for SMTP)...}
  88. TheSASLList := TIdSASLList.Create(nil);
  89. ThePassProvider := TIdUserPassProvider.Create(nil);
  90. TheSASLLogin := TIdSASLLogin.Create(nil);
  91. {$ENDIF}
  92. TheSmtp.Host := Edit1.Text;
  93. {$IFDEF INDY100}
  94. {TheSmtp.AuthenticationType := atNone; {Could use (atNone, atUserPass, atAPOP, atSASL) }
  95. TheSmtp.SASLMechanisms := TheSASLList;
  96. ThePassProvider.Username := Edit2.Text;
  97. ThePassProvider.Password := Edit3.Text;
  98. TheSASLLogin.UserPassProvider := ThePassProvider;
  99. TheSASLList.Add(TheSASLLogin);
  100. {$ELSE}
  101. TheSmtp.Username := Edit2.Text;
  102. TheSmtp.Password := Edit3.Text;
  103. {$ENDIF}
  104. formEncoderPlayground.SetupEmail;
  105. //Add From, To...
  106. formEncoderPlayground.TheMsg.From.Address := Edit5.Text;
  107. formEncoderPlayground.TheMsg.Recipients.Add.Address := Edit4.Text;
  108. formEncoderPlayground.TheMsg.Subject := Edit6.Text;
  109. {$IFDEF INDY100}
  110. TheSmtp.Connect;
  111. {$ELSE}
  112. TheSmtp.Connect(30000);
  113. {$ENDIF}
  114. TheSmtp.Send(formEncoderPlayground.TheMsg);
  115. TheSmtp.Disconnect;
  116. ShowMessage('Email apparently successfully sent.');
  117. ModalResult := mrOK;
  118. end;
  119. procedure TSendEmail.FormActivate(Sender: TObject);
  120. var
  121. TheParams: TStringList;
  122. begin
  123. //See if there are saved params to display...
  124. if FileExists('\IndyEncoderSmtp.dat') = True then begin
  125. //Save the settings...
  126. TheParams:= TStringList.Create;
  127. TheParams.LoadFromFile('C:\IndyEncoderSmtp.dat');
  128. Edit1.Text := TheParams.Values['SmtpServer'];
  129. Edit2.Text := TheParams.Values['SmtpUsername'];
  130. Edit3.Text := TheParams.Values['SmtpPassword'];
  131. Edit4.Text := TheParams.Values['SmtpTo'];
  132. Edit5.Text := TheParams.Values['SmtpFrom'];
  133. Edit6.Text := TheParams.Values['SmtpSubject'];
  134. TheParams.Destroy;
  135. end;
  136. end;
  137. end.