SMTPBox.pas 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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: 11273: SMTPBox.pas
  11. {
  12. { Rev 1.0 11/12/2002 09:19:42 PM JPMugaas
  13. { Initial check in. Import from FTP VC.
  14. }
  15. unit SMTPBox;
  16. interface
  17. uses
  18. IndyBox;
  19. type
  20. TSMTPBox = class(TIndyBox)
  21. public
  22. procedure Test; override;
  23. end;
  24. implementation
  25. uses
  26. IdMessage, IdSMTP,
  27. SysUtils;
  28. var
  29. GSMTP: string = '';
  30. GEMailAddr: string = '';
  31. { TSMTPBox }
  32. procedure TSMTPBox.Test;
  33. var
  34. LMsg: TIdMessage;
  35. begin
  36. LMsg := TIdMessage.Create(nil); try
  37. with LMsg do begin
  38. From.Address := GlobalParamValue('EMail Address');
  39. Recipients.Add.Address := From.Address;
  40. Subject := 'SMTP Box Test';
  41. Body.Add('Hello this is a test message from the SMTP Box.');
  42. Check(Body.Count = 1, 'Body line count mismatch.');
  43. end;
  44. with TIdSMTP.Create(nil) do try
  45. Host := GlobalParamValue('SMTP Server');
  46. Connect; try
  47. Status('Connected to ' + Host);
  48. Check(Connected, 'Connected does not reflect properly.');
  49. Send(LMsg);
  50. Status('Message sent to ' + LMsg.Recipients[0].Address);
  51. finally Disconnect; end;
  52. Status('Disconnected.');
  53. Check(not Connected, 'Connected does not reflect properly.');
  54. finally Free; end;
  55. finally FreeAndNil(LMsg); end;
  56. end;
  57. initialization
  58. TIndyBox.RegisterBox(TSMTPBox, 'SMTP Client', 'Clients');
  59. end.