TSmtpCli.OnRequestDone

From Overbyte
Revision as of 17:09, 1 July 2010 by Frla (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Main page -> ICS components reference -> TSmtpCli -> OnRequestDone

Definition

procedure (Sender: TObject; RqType: TSmtpRequest; ErrCode: Word) of object;

  • Sender : the client which fired the event
  • RqType : type of the request.
  • ErrCode : error code for the request. If it is 0, there was no error.

Description

This event will fire when the server has sent a response to your request and all data transfers has been done.

Examples

This is a sample of how to handle a common set of responses. LogMsg method is just a call to a procedure that output information visually in a memo.

<syntaxhighlight lang="delphi">

 if (error > 0) then
 begin
   logMsg('Service Error occured RqType:'+inttostr(integer(RqType))+' Error:'+vartostr(error));
   Exit;
 end;
 
 if RqType = smtpConnect then
 begin
   logMsg('Sending HELO');
   Smtp.Helo
 end
 else
 if RqType = smtpOpen then
 begin
   //open is easiest to use when you have the need for authentication
   logMsg('smtOpen, sending MailFrom');
   Smtp.MailFrom;
 end
 else
 if RqType = smtpHelo then
 begin
   logMsg('Sending from');
   Smtp.MailFrom;
 end
 else
 if RqType = smtpMailFrom then
 begin
   logMsg('Sending to');
   Smtp.RcptTo;
 end
 else
 if RqType = smtpRcptTo then
 begin
   logMsg('Sending data');
   Smtp.Data;
 end
 else
 if RqType = smtpData then
 begin
   //here you need to generate the e-mail, and trigger more...
   if SendEmailQryEMAILID.AsString <>  then
   begin
     logMsg('Sending next email');
     generateSingleEmail; //a procedure i use to create my e-mail
     Smtp.MailFrom;
   end
   else
   begin
     logMsg('No more email to send, quitting.');
     Smtp.Quit
   end;
 end
 else
 if RqType = smtpQuit then
 begin
   logMsg('SMTP connection closed');
 end;

</syntaxhighlight>


Best practices

nothing yet