SMTPIndySendMail

From RiskWiki

Jump to: navigation, search

Smart email sender

Language: Delphi 7 - 2007


Provides a wrapper for Indy10 email library and supports html & text, attachments and embedded images in email.

The routine automatically generates a text version of HTML emails and sets the MIME attribute to text/alternative, handling A links to provide the HREF portion if the descriptive portion is different from the HREF portion in the text version.

The routine is therefore spam-assassin safe.

HTML emails are BASE 64 MIME encoded, while the text part is UTF-8 and Base 64 MIMe Encoded.


Requires: TMailMessage.



uses EMailUnit, IdEMailAddress, Messages,  SysUtils,  Classes;

type

//This class will be used to store information about one picture for embedded images in emails.


  TbpcHTMLImageItem = class (TCollectionItem)
    public
      Stream: TMemoryStream;
      Name, ContentType: AnsiString;   //TRVAnsiString
      constructor Create(Collection: TCollection); override;
      destructor Destroy; override;
  end;

//Collection of TbpcHTMLImageItem for embedded images in emails

  TbpcHTMLImagesCollection = class (TCollection)
  private
    function GetItem(Index: Integer): TbpcHTMLImageItem;
    procedure SetItem(Index: Integer; const Value: TbpcHTMLImageItem);
    public
      constructor Create;
      property Items[Index: Integer]: TbpcHTMLImageItem read GetItem write SetItem; default;
  end;

// Main Mail Sender
function MailToSMTP(AMailMessage : TMailMessage; out AErrorMessage : String;
  ASMTPPort : Integer; const ASMTPHostAddress, ASMTPUserID, ASMTPUserPWD, ASMTPFromAddress, ASMTPFromName : String; ASMTPReplyToEmail : string=''; ASMTPReplyToName : string='';
  Attachments : TStringList=nil; HTMLImages : TbpcHTMLImagesCollection=nil ) : Boolean;


BackLinks



CopyRight Bishop Phillips Consulting Pty Ltd 1997-2012 ( SMTPIndySendMail )
Personal tools