Difference between revisions of "OverbyteIcsSmtpProt.pas"

From Overbyte
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 63: Line 63:
 
  TCustomSmtpClient = class(TIcsWndControl) { Base component, implementing the transport, without MIME support }
 
  TCustomSmtpClient = class(TIcsWndControl) { Base component, implementing the transport, without MIME support }
 
  TSmtpCli = class(TCustomSmtpClient) { Descending component adding MIME (file attach) support }
 
  TSmtpCli = class(TCustomSmtpClient) { Descending component adding MIME (file attach) support }
  TSyncSmtpCli = class(TSmtpCli) { TSyncSmtpCli adds synchronous functions = reduced performance }
+
  TSyncSmtpCli = class(TSmtpCli) { TSyncSmtpCli adds synchronous functions = reduced performance / need to be multi-threading }
 
  TCustomSslSmtpCli = class(TSyncSmtpCli) { adds SSL support to TSmtpCli }
 
  TCustomSslSmtpCli = class(TSyncSmtpCli) { adds SSL support to TSmtpCli }
 
  THtmlSmtpCli = class(TCustomSslSmtpCli) { if you have enabled SSL support}
 
  THtmlSmtpCli = class(TCustomSslSmtpCli) { if you have enabled SSL support}
 
  THtmlSmtpCli = class(TSyncSmtpCli) { if you have not enabled SSL support}
 
  THtmlSmtpCli = class(TSyncSmtpCli) { if you have not enabled SSL support}
 
  TSslHtmlSmtpCli = class(THtmlSmtpCli) { if you have enabled SSL support}
 
  TSslHtmlSmtpCli = class(THtmlSmtpCli) { if you have enabled SSL support}
 +
 +
== Selecting Component for use ==
 +
There are 7 classes in the SMTP client tree, which cover from sending very simple emails to the exceedingly fancy in HTML tags and delivered by SSL. If you wanted everything just in case the TSslHtmlSmtpCli would be it, however sending simple reports as attachments to the local in house email server only needs TSmtpCli as the sample demo OverbyteIcsMailSnd1.pas demonstrates.  The factors listed are: file attachments? (= MIME support needed?), HTML needed?, SSL needed? and synchronous functions.

Latest revision as of 19:39, 8 January 2016

Main Page -> OverbyteIcsSmtpProt.pas

Overview

Based on ICS revision 1264 source - v8.18

Support file attachement using MIME format (RFC-1521, RFC-2045)
Support authentification (RFC-2104)
Support HTML mail with embedded images.

Definitions

Here the definitions are sorted into more readable format:

Constant Definitions

SmtpEMailSeparators = [';', ','];
SmtpDefEncArray : array [0..3] of AnsiString = ('7bit', '8bit', 'quoted-printable', 'base64');

State / Set Definitions

TSmtpDefaultEncoding = (smtpEnc7bit, smtpEnc8bit, smtpEncQuotedPrintable, smtpEncBase64);
TSmtpSendMode = (smtpToSocket, smtpToStream, smtpCopyToStream);
TSmtpState = (smtpReady, smtpDnsLookup, smtpConnecting, smtpConnected, smtpInternalReady, smtpWaitingBanner, smtpWaitingResponse, smtpAbort, smtpInternalBusy);
TSmtpMimeState = (smtpMimeIntro, smtpMimePlainText, smtpMimeHtmlText, smtpMimeImages, smtpMimeAttach, smtpMimeDone);
TSmtpRequest = (smtpConnect, smtpHelo, smtpMailFrom, smtpVrfy, smtpRcptTo, smtpData, smtpQuit, smtpRset, smtpOpen, smtpMail, smtpEhlo, smtpAuth, smtpStartTls, smtpCalcMsgSize, smtpMailFromSIZE, smtpToFile, smtpCustom);
TSmtpProxyType = (smtpNoProxy, smtpSocks4, smtpSocks4A, smtpSocks5, smtpHttpProxy);
TSmtpFct = (smtpFctNone, smtpFctHelo, smtpFctConnect, smtpFctMailFrom, smtpFctRcptTo, smtpFctData, smtpFctVrfy, smtpFctQuit, smtpFctRset, smtpFctEhlo, smtpFctAuth ,smtpFctStartTls ,smtpFctCalcMsgSize ,smtpFctMailFromSIZE);
TSmtpFctSet = set of TSmtpFct;
TSmtpContentType = (smtpHtml, smtpPlainText);
TSmtpAuthType = (smtpAuthNone, smtpAuthPlain, smtpAuthLogin, smtpAuthCramMD5, smtpAuthCramSha1, smtpAuthNtlm, smtpAuthAutoSelect);
TSmtpShareMode = (smtpShareCompat, smtpShareExclusive, smtpShareDenyWrite, smtpShareDenyRead, smtpShareDenyNone);
TSmtpPriority = (smtpPriorityNone, smtpPriorityHighest, smtpPriorityHigh, smtpPriorityNormal, smtpPriorityLow, smtpPriorityLowest);
TSmtpEncoding = (smtpEncodeNone, smtpEncodeBase64, smtpEncodeQP);
TSmtpBeforeOpenFileAction = (smtpBeforeOpenFileNone, smtpBeforeOpenFileNext, smtpBeforeOpenFileAbort);
TSmtpAfterOpenFileAction = (smtpAfterOpenFileNone, smtpAfterOpenFileNext, smtpAfterOpenFileRetry, smtpAfterOpenFileAbort);
TSmtpRcptToErrorAction = (srteAbort, srteRetry, srteIgnore);
TSmtpSslType = (smtpTlsNone, smtpTlsImplicit, smtpTlsExplicit);

Event Definitions

TSmtpBeforeFileOpenEvent = procedure(Sender : TObject; Idx : Integer; FileName : String; var Action : TSmtpBeforeOpenFileAction) of object;
TSmtpAfterFileOpenEvent = procedure(Sender : TObject; Idx : Integer; FileName : String; E : Exception; var Action : TSmtpAfterOpenFileAction) of object;
TSmtpRcptToErrorEvent = procedure(Sender : TObject; ErrorCode : Word; RcptNameIdx : Integer; var Action : TSmtpRcptToErrorAction) of object;
TSmtpMessageDataSentEvent = procedure(Sender : TObject; Size : Integer) of object;
TSmtpFileOpenEvent = procedure(Sender : TObject; Idx : Integer; FileName : String; var Stream : TStream) of object;
TSmtpDisplay = procedure(Sender : TObject; Msg : String) of object;
TSmtpHeaderLineEvent = procedure(Sender : TObject; Msg : Pointer; Size : Integer) of object;
TSmtpProcessHeaderEvent = procedure(Sender : TObject; HdrLines : TStrings) of object;
TSmtpGetDataEvent = procedure(Sender : TObject; LineNum : Integer; MsgLine : Pointer; MaxLen : Integer; var More: Boolean) of object;
TSmtpRequestDone = procedure(Sender : TObject; RqType : TSmtpRequest; ErrorCode : Word) of object;
TSmtpAttachmentContentType = procedure(Sender : TObject; FileNumber : Integer; var FileName : String; var ContentType : String) of object;
TSmtpAttachmentContentTypeEh = procedure(Sender : TObject; FileNumber : Integer; var FileName : String; var ContentType : String; var AttEncoding : TSmtpEncoding) of object;
TSmtpAttachHeader = procedure(Sender : TObject; FileNumber : Integer; FileName : String; HdrLines : TStrings) of object;
TSmtpNextProc = procedure of object;

Support Class Definitions

TSmtpHeaderLines = class(TStringList)
TSmtpMessageText = class(TObject)
SmtpException = class(Exception);

Support Functions

function RFC822DateTime(t : TDateTime) : String;
function ParseEmail(FriendlyEmail : String; var FriendlyName : String) : String;
function GenerateMessageID : String;
function SmtpRqTypeToStr(RqType: TSmtpRequest): ShortString;
function SmtpCliErrorMsgFromErrorCode(ErrCode: Word): String;

Main Component Definitions

TCustomSmtpClient = class(TIcsWndControl) { Base component, implementing the transport, without MIME support }
TSmtpCli = class(TCustomSmtpClient) { Descending component adding MIME (file attach) support }
TSyncSmtpCli = class(TSmtpCli) { TSyncSmtpCli adds synchronous functions = reduced performance / need to be multi-threading }
TCustomSslSmtpCli = class(TSyncSmtpCli) { adds SSL support to TSmtpCli }
THtmlSmtpCli = class(TCustomSslSmtpCli) { if you have enabled SSL support}
THtmlSmtpCli = class(TSyncSmtpCli) { if you have not enabled SSL support}
TSslHtmlSmtpCli = class(THtmlSmtpCli) { if you have enabled SSL support}

Selecting Component for use

There are 7 classes in the SMTP client tree, which cover from sending very simple emails to the exceedingly fancy in HTML tags and delivered by SSL. If you wanted everything just in case the TSslHtmlSmtpCli would be it, however sending simple reports as attachments to the local in house email server only needs TSmtpCli as the sample demo OverbyteIcsMailSnd1.pas demonstrates. The factors listed are: file attachments? (= MIME support needed?), HTML needed?, SSL needed? and synchronous functions.