EMailUnit
Email Message Wrapper Class
Language: Delphi 7 - 2007
Simple message wrapper with builtin styles bug fix.
type TMailConnectType = (mctNotAssigned, mctSMTP, mctOutlook); TMailMessage = class private FBCC: String; FCC: String; FSendTo: String; function GetBCC : String; function GetCC : String; function GetSendTo : String; function GetMIMEType : String; //JGB 21/3/07 added mime handling procedure SetMIMEType( sValue : String); //JGB 21/3/07 added mime handling protected // Parse the input E-mail recipient string and replace ';' with ',' character. function GetRecipientValue(const AInputValue : String) : String; public From, Subject, Body, MIMEType : String; // JGB 21/3/07 - access this field directly to find out the MIMEType procedure FixHTMLStyleLineStart; // JGB 22/3/07 - Hack to repair a transmission error that results in the leading '.' of a line being dropped in styles during transmission of HTML procedure ClearVariableFields; property SendTo : String read GetSendTo write FSendTo; property CC : String read GetCC write FCC; property BCC : String read GetBCC write FBCC; property ContentType : String read GetMIMEType write SetMIMEType; //JGB 21/3/07 added mime handling. Automatically translates //'plain','html','xml','rtf', 'pdf' and allows anything else through ///as-is end; const CMailConnectNotAssigned = 'Mail connection is not assigned';
The wrapper uses a simplified MIME type specifier. To assist the conversion code is preproduced below:
//JGB 21/3/07 added mime handling // Simple routine to map short strings to full mime types - just simplifies enduser handling a bit // Automatically translates 'plain','html','xml','rtf' and allows anything else through as-is function TMailMessage.GetMIMEType: String; begin result := ''; case bpcWSIndexOfList( MIMEType, ['','text/plain','text/html','text/xml','text/richtext','application/pdf'] ) of -1 : result := MIMEType; // Unknown Type - return it anyway 0 : result := 'plain'; 1 : result := 'plain'; 2 : result := 'html'; 3 : result := 'xml'; 4 : result := 'rtf'; 5 : result := 'pdf'; end; end; //JGB 21/3/07 added mime handling // Simple routine to map short strings to full mime types - just simplifies enduser handling a bit // Automatically translates 'plain','html','xml','rtf' and allows anything else through as-is procedure TMailMessage.SetMIMEType(sValue: String); begin case bpcWSIndexOfList( sValue, ['','plain','html','xml','rtf','pdf'] ) of -1 : MIMEType := sValue; // Unknown Type - allow direct assignment anyway 0 : MIMEType := 'text/plain'; 1 : MIMEType := 'text/plain'; 2 : MIMEType := 'text/html'; 3 : MIMEType := 'text/xml'; 4 : MIMEType := 'text/richtext'; 5 : MIMEType := 'application/pdf'; end; end;