NMSMTP.pas
资源名称:FastNet.rar [点击查看]
上传用户:szzdds
上传日期:2013-09-18
资源大小:293k
文件大小:26k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit NMsmtp;
- {$X+}
- {$R-}
- {$IFDEF VER100}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER110}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER120}
- {$DEFINE NMF3}
- {$ENDIF}
- {$IFDEF VER125}
- {$DEFINE NMF3}
- {$ENDIF}
- interface
- uses
- Classes, PSock, sysutils, NMuue, NMExtstr, NMConst;
- {$IFDEF VER110}
- {$OBJEXPORTALL On}
- {$ENDIF}
- {$IFDEF VER120}
- {$OBJEXPORTALL On}
- {$ENDIF}
- {$IFDEF VER125}
- {$OBJEXPORTALL On}
- {$ENDIF}
- const
- SMTP_PORT = 25;
- // CompName ='TNMSMTP';
- // Major_Version='4';
- // Minor_Version='03';
- // Date_Version ='020398';
- CRLF = #13#10;
- hiFromAddress = 1;
- hiToAddress = 2;
- const {protocol}
- Cons_Helo = 'HELO ';
- Cons_Quit = 'QUIT';
- Cons_Rset = 'RSET';
- Cons_From = 'MAIL FROM:<';
- Cons_To = 'RCPT TO:<';
- Cons_Date = 'DATA';
- Cons_Expn = 'EXPN ';
- Cons_Vrfy = 'VRFY ';
- Cons_Head_subj = 'Subject';
- Cons_Head_from = 'From: ';
- Cons_Head_To = 'To: ';
- Cons_Head_CC = 'CC: ';
- Cons_Head_mail = 'X-Mailer';
- Cons_Head_ReplyTo = 'Reply-To';
- Cons_Head_Date = 'Date';
- Cons_Head_mime = 'Mime-Version: 1.0';
- Cons_Head_disp = 'Content-Disposition: attachment; filename="';
- Cons_Head_ba64 = 'Content-Transfer-Encoding: base64';
- Cons_Head_appl = 'Content-Type: application/octet-stream; name="';
- Cons_Head_text = 'Content-Type: text/plain; charset=';
- Cons_Head_Enriched = 'Content-Type: text/enriched; charset=';
- Cons_Head_Sgml = 'Content-Type: text/sgml; charset=';
- Cons_Head_TabSeperated = 'Content-Type: text/tab-separated-values; charset=';
- Cons_Head_mtHtml = 'Content-Type: text/html; charset=';
- // Cons_Head_text2 = 'Content-Type: text/plain, charset="iso-8859-1"';
- Cons_Head_mult = 'Content-Type: multipart/mixed; boundary="';
- Cons_Head_7Bit = 'Content-Transfer-Encoding: 7Bit';
- type
- TSubType = (mtPlain, mtEnriched, mtSgml, mtTabSeperated, mtHtml);
- THeaderInComplete = procedure(var handled: boolean; hiType: integer) of object;
- TRecipientNotFound = procedure(Recipient: string) of object;
- TMailListReturn = procedure(MailAddress: string) of object;
- TFileItem = procedure(Filename: string) of object;
- TPostMessage = class(TPersistent)
- private
- FFromName, FFrom, FSubject, FLocalProgram, FDate, FReplyTo: string;
- FAttachments, FTo, FCC, FBCC: TStringList;
- FBody: TStringList;
- protected
- procedure SetLinesTo(Value: TStringList);
- procedure SetLinesCC(Value: TStringList);
- procedure SetLinesBCC(Value: TStringList);
- procedure SetLinesBody(Value: TStringList);
- procedure SetLinesAttachments(Value: TStringList);
- public
- constructor Create;
- destructor Destroy; override;
- published
- property FromAddress: string read FFrom write FFrom;
- property FromName: string read FFromName write FFromName;
- property ToAddress: TStringList read FTo write SetLinesTo;
- property ToCarbonCopy: TStringList read FCC write SetLinesCC;
- property ToBlindCarbonCopy: TStringList read FBCC write SetLinesBCC;
- property Body: TStringList read FBody write SetLinesBody;
- property Attachments: TStringList read FAttachments write SetLinesAttachments;
- property Subject: string read FSubject write FSubject;
- property LocalProgram: string read FLocalProgram write FLocalProgram;
- property Date: string read FDate write FDate;
- property ReplyTo: string read FReplyTo write FReplyTo;
- end;
- TNMSMTP = class(TPowerSock)
- private
- FCharset: string;
- FOnConnect: TNotifyEvent;
- FPostMessage: TPostMessage;
- FsenFmem: TMemoryStream;
- (*{$IFDEF NMF3}
- FSendFile: TS_BufferStream;
- {$ELSE} *)
- FSendFile: TMemoryStream;
- //{$ENDIF}
- FFinalHeader: TExStringList;
- FTransactionInProgress, FAbort: boolean;
- FUserID, FBoundary: string;
- FSubType: TSubType;
- FOnHeaderInComplete: THeaderInComplete;
- FOnSendStart, FOnSuccess, FOnFailure: TNotifyEvent;
- FOnEncodeStart, FOnEncodeEnd: TFileItem;
- FOnAttachmentNotFound: TFileItem;
- FRecipientNotFound {,FMessageSent}: TRecipientNotFound;
- FMailListReturn: TMailListReturn;
- FOnAuthenticationFailed: THandlerEvent;
- fUUMethod: UUMethods;
- FClearParams: boolean;
- WaitForReset: integer;
- {$IFDEF NMDEMO}
- DemoStamped: boolean;
- {$ENDIF}
- procedure ReadExtraLines(var ReplyMess: string);
- procedure SendAttachments(i: integer);
- procedure AssembleMail;
- procedure AbortResume(Sender: TObject);
- procedure SetFinalHeader(Value: TExStringList);
- //function CreateTemporaryFileName: string;
- protected
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Connect; override;
- procedure Disconnect; override;
- procedure SendMail;
- procedure Abort; override;
- procedure ClearParameters;
- function ExtractAddress(TotalAddress: string): string;
- function Verify(UserName: string): boolean;
- function ExpandList(MailList: string): boolean;
- published
- property OnPacketSent;
- property OnConnectionRequired;
- property OnConnect: TNotifyEvent read FOnConnect write FOnConnect;
- property UserID: string read FUserID write FUserID;
- property PostMessage: TPostMessage read FPostMessage write FPostMessage;
- property FinalHeader: TExStringList read FFinalHeader write SetFinalHeader;
- property EncodeType: UUMethods read fUUMethod write fUUMethod;
- property ClearParams: boolean read FClearParams write FClearParams;
- property SubType: TSubType read FSubType write FSubType;
- property Charset: string read FCharset write FCharset;
- property OnRecipientNotFound: TRecipientNotFound read FRecipientNotFound write FRecipientNotFound;
- property OnHeaderIncomplete: THeaderInComplete read FOnHeaderInComplete write FOnHeaderInComplete;
- property OnSendStart: TNotifyEvent read FOnSendStart write FOnSendStart;
- property OnSuccess: TNotifyEvent read FOnSuccess write FOnSuccess;
- property OnFailure: TNotifyEvent read FOnFailure write FOnFailure;
- property OnEncodeStart: TFileItem read FOnEncodeStart write FOnEncodeStart;
- property OnEncodeEnd: TFileItem read FOnEncodeEnd write FOnEncodeEnd;
- property OnMailListReturn: TMailListReturn read FMailListReturn write FMailListReturn;
- property OnAttachmentNotFound: TFileItem read FOnAttachmentNotFound write FOnAttachmentNotFound;
- property OnAuthenticationFailed: THandlerEvent read FOnAuthenticationFailed write FOnAuthenticationFailed;
- end;
- implementation
- uses
- Windows;
- var
- mailcount: integer;
- function StripCRLF(InStr: string): string;
- begin
- if InStr <> '' then
- if InStr[Length(InStr)] = #10 then
- Result := Copy(InStr, 1, Length(InStr) - 2)
- else Result := InStr;
- end;
- {*******************************************************************************************
- Constructor - Create String Lists to hold body, attachment list and distribution lists.
- Sets Default port and clears Transaction in Progress flag.
- ********************************************************************************************}
- constructor TNMSMTP.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- try
- Port := SMTP_PORT;
- EncodeType := UUMime;
- FTransactionInProgress := FALSE;
- FPostMessage := TPostMessage.Create;
- FFinalHeader := TExStringList.Create;
- FsenFmem := TMemoryStream.Create;
- (*{$IfDef NMF3}
- FSendFile := TS_BufferStream.create(FsenFmem);
- {$ELSE} *)
- FSendFile := TMemoryStream.Create;
- // {$ENDIF}
- FClearParams := TRUE;
- FSubType := mtPlain;
- FCharset := 'GB2312';
- OnAbortRestart := AbortResume;
- WaitForReset := 2;
- except
- Destroy;
- end;
- end;
- {*******************************************************************************************
- Constructor - Destroys String Lists holding body, attachment list and distribution lists.
- ********************************************************************************************}
- destructor TNMSMTP.Destroy;
- begin
- if FPostMessage <> nil then
- FPostMessage.free;
- FFinalHeader.free;
- FSendFile.free;
- FsenFmem.free;
- inherited Destroy;
- end;
- {*******************************************************************************************
- Connect - Calls inherited socket connect and gets reply. Sends Greeting to server
- and gets reply.
- ********************************************************************************************}
- procedure TNMSMTP.Connect;
- var
- ReplyMess: string;
- TryCt: integer;
- ConnCalled, handled: boolean;
- Done: boolean;
- begin
- ConnCalled := FALSE;
- Done := FALSE;
- if FTransactionInProgress then
- ConnCalled := TRUE
- else
- FTransactionInProgress := TRUE;
- try
- inherited Connect;
- try
- ReplyMess := Readln;
- ReadExtraLines(ReplyMess);
- if ReplyNumber > 399 then
- raise Exception.Create(ReplyMess);
- TryCt := 0;
- repeat
- ReplyMess := Transaction(Cons_Helo + FUserID);
- ReadExtraLines(ReplyMess);
- if ReplyNumber > 299 then
- if TryCt > 0 then
- raise Exception.Create(Cons_Msg_Auth_Fail)
- else if not Assigned(FOnAuthenticationFailed) then
- raise Exception.Create(Cons_Msg_Auth_Fail)
- else
- begin
- handled := FALSE;
- FOnAuthenticationFailed(handled);
- if not handled then
- raise Exception.Create(Cons_Msg_Auth_Fail);
- TryCt := TryCt + 1;
- end;
- until ReplyNumber < 299;
- Done := TRUE;
- except
- Disconnect;
- raise
- end;
- finally
- if not ConnCalled then
- FTransactionInProgress := FALSE;
- if Done then
- if Assigned(FOnConnect) then
- FOnConnect(self);
- end;
- end;
- {*******************************************************************************************
- Disconnect - Sends Quit message to server and gets Reply. Calls inherited disconnect to
- close socket.
- ********************************************************************************************}
- procedure TNMSMTP.Disconnect;
- var ReplyMess: string;
- begin
- Beencanceled := FALSE;
- try
- ReplyMess := Transaction(Cons_Quit);
- if ReplyNumber > 339 then
- raise Exception.Create(ReplyMess);
- finally
- inherited Disconnect;
- end;
- end;
- {*******************************************************************************************
- SendMail - Posts a mail message to the server
- ********************************************************************************************}
- procedure TNMSMTP.SendMail;
- var
- ReplyMess: string;
- i, TryCt: integer;
- Done, handled: boolean;
- TAdd: string;
- begin
- if not FTransactionInProgress then
- begin
- Done := FALSE;
- FTransactionInProgress := TRUE;
- try
- AssembleMail;
- CertifyConnect;
- TryCt := 0;
- repeat
- if (FPostMessage.FFrom = '') or ((FPostMessage.FTo.count = 0) and (FPostMessage.FCC.count = 0) and (FPostMessage.FBCC.count = 0)) then
- if TryCt > 0 then
- raise Exception.Create(sSMTP_Msg_Incomp_Head)
- else if not Assigned(FOnHeaderInComplete) then
- raise Exception.Create(sSMTP_Msg_Incomp_Head)
- else
- begin
- handled := FALSE;
- if FPostMessage.FFrom = '' then
- FOnHeaderInComplete(handled, hiFromAddress)
- else
- FOnHeaderInComplete(handled, hiToAddress);
- if not handled then
- raise Exception.Create(sSMTP_Msg_Incomp_Head);
- TryCt := TryCt + 1;
- end;
- until (FPostMessage.FFrom <> '') and ((FPostMessage.FTo.count <> 0) or (FPostMessage.FCC.count <> 0) or (FPostMessage.FBCC.count <> 0));
- if Assigned(FOnSendStart) then
- FOnSendStart(self);
- FAbort := FALSE;
- ReplyMess := Transaction(Cons_Rset);
- if ReplyNumber > 399 then
- raise Exception.Create(ReplyMess);
- if not FAbort then
- ReplyMess := Transaction(Cons_From + FPostMessage.FFrom + '>');
- if ReplyNumber > 399 then
- raise Exception.Create(ReplyMess);
- if not FAbort then
- for i := 1 to FPostMessage.FTo.count do
- begin
- TAdd := ExtractAddress(StripCRLF(FPostMessage.FTo.strings[i - 1]));
- if TAdd <> '' then
- begin
- ReplyMess := Transaction(Cons_To + TAdd + '>');
- if ReplyNumber > 300 then
- if Assigned(FRecipientNotFound) then
- FRecipientNotFound(FPostMessage.FTo.strings[i - 1]);
- end;
- end;
- if not FAbort then
- for i := 1 to FPostMessage.FCC.count do
- begin
- TAdd := ExtractAddress(StripCRLF(FPostMessage.FCC.strings[i - 1]));
- if TAdd <> '' then
- begin
- ReplyMess := Transaction(Cons_To + TAdd + '>');
- if ReplyNumber > 300 then
- if Assigned(FRecipientNotFound) then
- FRecipientNotFound(FPostMessage.FTo.strings[i - 1]);
- end;
- end;
- if not FAbort then
- for i := 1 to FPostMessage.FBCC.count do
- begin
- TAdd := ExtractAddress(FPostMessage.FBCC.strings[i - 1]);
- if TAdd <> '' then
- begin
- ReplyMess := Transaction(Cons_To + TAdd + '>');
- if ReplyNumber > 300 then
- if Assigned(FRecipientNotFound) then
- FRecipientNotFound(FPostMessage.FTo.strings[i - 1]);
- end;
- end;
- if not FAbort then
- ReplyMess := Transaction(Cons_Date);
- if ReplyNumber > 399 then
- raise Exception.Create(ReplyMess);
- Write(FFinalHeader.Text + CRLF);
- SendStream(FSendFile);
- ReplyMess := Transaction(CRLF + '.');
- if ReplyNumber > 399 then
- begin
- if Assigned(FOnFailure) then
- FOnFailure(self);
- raise Exception.Create(ReplyMess);
- end
- else
- Done := TRUE;
- if FAbort then
- ReplyMess := Transaction(CRLF + Cons_Rset);
- if FClearParams then
- ClearParameters;
- finally
- FTransactionInProgress := FALSE;
- if Done then
- if Assigned(FOnSuccess) then
- FOnSuccess(self);
- end;
- end;
- end;
- procedure TNMSMTP.AssembleMail;
- var
- i: integer;
- Tstr: string;
- begin
- FFinalHeader.clear;
- FFinalHeader.add(Cons_Head_from + FPostMessage.FFromName + '<' + FPostMessage.FFrom + '>');
- for i := 1 to FPostMessage.FTo.count do
- begin
- if (i = 1) then
- Tstr := Cons_Head_To + StripCRLF(FPostMessage.FTo.strings[0])
- else
- Tstr := Tstr + ',' + StripCRLF(FPostMessage.FTo.strings[i - 1]);
- if (i = FPostMessage.FTo.count) then
- FFinalHeader.add(Tstr);
- end;
- for i := 1 to FPostMessage.FCC.count do
- begin
- if (i = 1) then
- Tstr := Cons_Head_CC + StripCRLF(FPostMessage.FCC.strings[0])
- else
- Tstr := Tstr + ',' + StripCRLF(FPostMessage.FCC.strings[i - 1]);
- if (i = FPostMessage.FCC.count) then
- FFinalHeader.add(Tstr);
- end;
- FFinalHeader.values[Cons_Head_subj] := FPostMessage.FSubject;
- FFinalHeader.values[Cons_Head_mail] := FPostMessage.FLocalProgram;
- if (FPostMessage.FReplyTo <> '') then
- FFinalHeader.values[Cons_Head_ReplyTo] := FPostMessage.FReplyTo;
- if (FPostMessage.FDate <> '') then
- FFinalHeader.values[Cons_Head_Date] := FPostMessage.FDate;
- FFinalHeader.add(Cons_Head_mime);
- if (FPostMessage.FAttachments.count = 0) then
- begin
- case FSubType of
- mtEnriched: FFinalHeader.add(Cons_Head_Enriched + FCharset);
- mtSgml: FFinalHeader.add(Cons_Head_Sgml + FCharset);
- mtTabSeperated: FFinalHeader.add(Cons_Head_TabSeperated + FCharset);
- mtHtml: FFinalHeader.add(Cons_Head_mtHtml + FCharset);
- else
- FFinalHeader.add(Cons_Head_text + FCharset);
- end;
- {FFinalHeader.add(Cons_Head_7Bit); }
- end
- else
- begin
- FBoundary := '====================54535' + TimeToStr(mailcount) + '====';
- inc(mailcount);
- FFinalHeader.add(Cons_Head_mult + FBoundary + '"');
- end;
- (* {$IfDef NMF3}
- FSendFile.Flushbuffer;
- {$ELSE} *)
- FSendFile.clear;
- // {$ENDIF}
- try
- if (FPostMessage.FAttachments.count = 0) then
- for i := 1 to FPostMessage.FBody.count do
- begin
- Tstr := FPostMessage.FBody[i - 1] + CRLF;
- if Tstr[1] = '.' then
- Tstr := '.' + Tstr;
- FSendFile.Write(Tstr[1], Length(Tstr));
- end
- else
- begin
- Tstr := '--' + FBoundary + CRLF + Cons_Head_text + FCharset + CRLF + CRLF;
- FSendFile.Write(Tstr[1], Length(Tstr));
- for i := 1 to FPostMessage.FBody.count do
- begin
- Tstr := FPostMessage.FBody[i - 1] + CRLF;
- if Tstr[1] = '.' then
- Tstr := '.' + Tstr;
- FSendFile.Write(Tstr[1], Length(Tstr));
- end;
- for i := 1 to FPostMessage.FAttachments.count do
- SendAttachments(i);
- Tstr := '--' + FBoundary + '--' + CRLF;
- FSendFile.Write(Tstr[1], Length(Tstr));
- end;
- FSendFile.Position := 0;
- finally
- {FSendFile.free; }
- end;
- end;
- {
- function TNMSMTP.CreateTemporaryFileName: string;
- var
- nBufferLength: DWord;
- lpPathName, lpTempFileName: PChar;
- begin
- Result := '';
- lpPathName := nil;
- lpTempFileName := nil;
- // first get the length of the tempory path
- nBufferLength := GetTempPath( 0, lpPathName );
- Win32Check( BOOL( nBufferLength ) );
- // Allocate a buffer of the specified length + 1
- lpPathName := AllocMem( nBufferLength );
- try
- // Get the tempory path
- Win32Check( BOOL( GetTempPath( nBufferLength, lpPathName ) ) );
- // Increase the tempory path to hold the file name also.
- lpTempFileName := AllocMem( 256 );
- try
- // Get the temporary file name
- Win32Check( BOOL( GetTempFileName( lpPathName, PChar( 'Buf' ), 0, lpTempFileName ) ) );
- // return the file name and path
- SetString( Result, lpTempFileName, StrLen( lpTempFileName ) );
- // Lastly free the buffers.
- finally
- FreeMem( lpPathName );
- end;
- finally
- FreeMem( lpTempFileName );
- end;
- if Result = '' then
- raise Exception.Create( 'Can''t create a temporary file' );
- end;
- }
- {*******************************************************************************************
- SendAttachments - Sends attachched file to server.
- ********************************************************************************************}
- procedure TNMSMTP.SendAttachments;
- var
- UUPROC: TNMUUProcessor;
- Tstr: string;
- // SFileS: TFileStream;
- SfileF: TFileStream;
- begin
- Tstr := '--' + FBoundary + CRLF;
- Tstr := Tstr + Cons_Head_appl + ExtractFileName(FPostMessage.FAttachments[i - 1]) + '"' + CRLF;
- Tstr := Tstr + Cons_Head_ba64 + CRLF;
- Tstr := Tstr + Cons_Head_disp + ExtractFileName(FPostMessage.FAttachments[i - 1]) + '"';
- Tstr := Tstr + CRLF + CRLF;
- FSendFile.Write(Tstr[1], Length(Tstr));
- //SfileS := nil;
- UUPROC := nil;
- try
- UUPROC := TNMUUProcessor.Create(self);
- // Tstr := CreateTemporaryFileName;
- // SFileS := TFileStream.create(Tstr, fmCreate);
- UUPROC.method := EncodeType;
- SfileF := TFileStream.Create(FPostMessage.FAttachments[i - 1], fmOpenRead);
- UUPROC.InPutStream := SfileF;
- UUPROC.OutPutStream := FSendFile;
- // uuproc.OutPutStream := SFileS;
- if Assigned(OnEncodeStart) then
- OnEncodeStart(FPostMessage.FAttachments[i - 1]);
- try
- UUPROC.encode;
- except
- on E: EFOpenError do
- begin
- if Assigned(OnAttachmentNotFound) then
- OnAttachmentNotFound(FPostMessage.FAttachments[i - 1]);
- raise;
- end;
- end;
- if Assigned(OnEncodeEnd) then
- OnEncodeEnd(FPostMessage.FAttachments[i - 1]);
- try
- //SFileS.position := 0;
- //FSendFile.CopyFrom(SFileS, SFileS.size);
- finally
- //SFileA.Free;
- SfileF.free;
- end;
- finally
- //SysUtils.DeleteFile( Tstr );
- FSendFile.Position := FSendFile.Size;
- Tstr := CRLF;
- FSendFile.Write(Tstr[1], Length(Tstr));
- //SfileS.Free;
- UUPROC.free
- end;
- end;
- {*******************************************************************************************
- Process Extra Lines in Transaction
- ********************************************************************************************}
- procedure TNMSMTP.ReadExtraLines;
- begin
- while (ReplyMess[1] = ' ') or (ReplyMess[4] = '-') do {If extra Lines}
- ReplyMess := Readln;
- end;
- {*******************************************************************************************
- Verify
- ********************************************************************************************}
- function TNMSMTP.Verify(UserName: string): boolean;
- var
- ReplyMess: string;
- begin
- CertifyConnect;
- ReplyMess := Transaction(Cons_Vrfy + UserName);
- if ReplyNumber > 251 then Result := FALSE else Result := TRUE;
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- procedure TNMSMTP.Abort;
- begin
- inherited Abort;
- (*if (not BeenCanceled) and Connected then
- begin
- if FTransactionInProgress then
- begin
- Cancel;
- end
- else
- begin
- inherited Disconnect;
- TMemoryStream(FIstream).clear;
- end;
- end; *)
- end;
- procedure TNMSMTP.AbortResume(Sender: TObject);
- begin
- inherited Disconnect;
- ClearInput;
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- function TNMSMTP.ExpandList(MailList: string): boolean;
- var
- ReplyMess: string;
- begin
- Result := FALSE;
- if not FTransactionInProgress then
- begin
- FTransactionInProgress := TRUE;
- try
- CertifyConnect;
- ReplyMess := Transaction(Cons_Expn + MailList);
- if ReplyNumber > 399 then
- Result := FALSE
- else
- begin
- Result := TRUE;
- if Assigned(OnMailListReturn) then
- OnMailListReturn(ReplyMess);
- ReadExtraLines(ReplyMess);
- end;
- finally
- FTransactionInProgress := TRUE;
- end;
- end;
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- function TNMSMTP.ExtractAddress(TotalAddress: string): string;
- begin
- if Pos('<', TotalAddress) > 0 then
- Result := NthWord(NthWord(TotalAddress, '<', 2), '>', 1)
- else if Pos(':', TotalAddress) > 0 then
- Result := NthWord(TotalAddress, ':', 2)
- else
- Result := TotalAddress;
- end;
- procedure TNMSMTP.SetFinalHeader(Value: TExStringList);
- begin
- FFinalHeader.assign(Value);
- end;
- {*******************************************************************************************
- Constructor - Create String Lists to hold body, attachment list and distribution lists.
- Sets Default port and clears Transaction in Progress flag.
- ********************************************************************************************}
- constructor TPostMessage.Create;
- begin
- inherited Create;
- FTo := TStringList.Create;
- FCC := TStringList.Create;
- FBCC := TStringList.Create;
- FBody := TStringList.Create;
- FAttachments := TStringList.Create;
- end;
- {*******************************************************************************************
- Constructor - Destroys String Lists holding body, attachment list and distribution lists.
- ********************************************************************************************}
- destructor TPostMessage.Destroy;
- begin
- FTo.free;
- FCC.free;
- FBCC.free;
- FAttachments.free;
- FBody.free;
- inherited Destroy;
- end;
- {*******************************************************************************************
- ClearParameters - Clears distribution lists and Attachments.
- ********************************************************************************************}
- procedure TNMSMTP.ClearParameters;
- begin
- FPostMessage.FTo.clear;
- FPostMessage.FCC.clear;
- FPostMessage.FBCC.clear;
- FPostMessage.FAttachments.clear;
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- procedure TPostMessage.SetLinesTo(Value: TStringList);
- begin
- FTo.assign(Value);
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- procedure TPostMessage.SetLinesCC(Value: TStringList);
- begin
- FCC.assign(Value);
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- procedure TPostMessage.SetLinesBCC(Value: TStringList);
- begin
- FBCC.assign(Value);
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- procedure TPostMessage.SetLinesBody(Value: TStringList);
- begin
- FBody.assign(Value);
- end;
- {*******************************************************************************************
- Aborts a transaction
- ********************************************************************************************}
- procedure TPostMessage.SetLinesAttachments(Value: TStringList);
- begin
- FAttachments.assign(Value);
- end;
- end.