Class SMTPClient() Professional

Class function of the SMTPClient class.

Description

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
:new()
Creates an instance of the SMTPClient class.
Methods for sending e-mails
:connect()
Connects to the SMTP server.
:disconnect()
Disconnects from the SMTP server.
:isConnected()
Checks if a connection is established
:send()
Sends an e-mail message to the SMTP server.
:setAuthentication()
Sets the method for authenticating the user.
:setConnectionSecurity()
Configures secure communication with the server.
:setProgressBlock()
Sets a code block for progress evaluation
Examples
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) 

PROCEDURE Main 
   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( "smtp.live.com", 587,,; 
                                         oLog, 2 ) 

   LOCAL oSender    := MailAddress():new( "panthera.roseus@hotmail.com" ) 
   LOCAL oRecipient := MailAddress():new( "panthera.roseus@hotmail.com" ) 
   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( "panthera.roseus@hotmail.com", "0924LargeCat" ) 
      IF oSmtp:send( oMail ) 
         ? "Message sent" 
      ELSE 
         ? "Unable to deliver message" 
      ENDIF 

      oSmtp:disconnect() 
   ELSE 
      ? "Unable to connect to mail server" 
   ENDIF 
RETURN 


/* 
 * User-defined class for log-data processing 
 */ 
CLASS LogWriter 
   EXPORTED: 
   INLINE METHOD write( cLogData ) 
      ? cLogData 
   RETURN 
ENDCLASS 
Feedback

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.