Class SMTPClient() Professional

Class function of the SMTPClient class.


Instances of the SMTPClient class are used to access an SMTP server via the Simple Mail Transfer Protocol (SMTP). This communication protocol is used for sending e-mail messages to a Mail Transport Agent (MTA). An SMTPClient connects via the TCP/IP network protocol to an e-mail server and then negotiates the parameters for sending messages. This so-called SMTP handshake is performed when the method :connect() is executed.

By default, e-mails are sent unencrypted as human-readable data. However, the SMTPClient class also supports establishing connections where all communication is encrypted via a Secure Socket Layer (SSL). See the method :new() for more details on setting up secure connections.

Class methods
Creates an instance of the SMTPClient class.
Methods for sending e-mails
Connects to the SMTP server.
Disconnects from the SMTP server.
Checks if a connection is established
Sends an e-mail message to the SMTP server.
Sets the method for authenticating the user.
Configures secure communication with the server.
Sets a code block for progress evaluation
Sending an e-mail via SSL
// This example outlines the steps required for 
// sending an e-mail to an SMTP server. The e-mail 
// is assembled using MailAddress objects and a 
// MIMEMessage object. The latter is passed to the 
// SMTPClient object which sends the e-mail to the 
// server. The server response is logged in a user 
// defined class. 

#pragma library("ASINET10.LIB") 

#define CRLF  Chr(13)+Chr(10) 

   LOCAL oLog       := LogWriter():new() 

   // Connect to the Windows Live SMTP server. Port number 
   // 587 implies a secure SSL connection. Use standard 
   // port 25 for unencrypted communication and for 
   // servers which do not support SSL. 
   LOCAL oSmtp      := SMTPClient():new( "", 587,,; 
                                         oLog, 2 ) 

   LOCAL oSender    := MailAddress():new( "" ) 
   LOCAL oRecipient := MailAddress():new( "" ) 
   LOCAL oMail      := MIMEMessage():new() 
   LOCAL cText 

   cText := "Happy Birthday to Jane" + CRLF + CRLF 
   cText += "Cheers" + CRLF 
   cText += "  Roseus" + CRLF 

   oMail:setFrom     ( oSender     ) 
   oMail:setSubject  ( "Greetings" ) 
   oMail:setMessage  ( cText       ) 
   oMail:addRecipient( oRecipient  ) 

   IF oSmtp:connect( "", "0924LargeCat" ) 
      IF oSmtp:send( oMail ) 
         ? "Message sent" 
         ? "Unable to deliver message" 

      ? "Unable to connect to mail server" 

 * User-defined class for log-data processing 
CLASS LogWriter 
   INLINE METHOD write( cLogData ) 
      ? cLogData 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.