The built-in functions in the SMTPSession class provide the ability to connect to an SMTP server with a variety of methods and send email and SMTP commands.

The SMTPSession class offers the following functionality:

  • New() Creates a new SMTP session object.
  • SetTimeout() and GetTimeout() to get or set the SMTP command timeout value.
  • Connect() to connect to an SMTP host.
  • InitContext() to initialize an SSL context for secure connections.
  • SecureLogin() and Login() to login to the SMTP server.
  • Close() to close an SMTP connection.
  • SendMessage() and SendCommand() to interact with the SMTP server.
  • GetLastError() to return a string for the last error that occured.

  • Class Methods Index

     o SMTPSession New ( String host, Integer port )
    Returns a new SMTPSession instance, or undefined if an error occured.

    Function Constants Index

    SMTPSession New() port parameters

     o SMTP_PORT
    The standard SMTP port, 25
     o SECURE_SMTP_PORT
    The standard Secure SMTP port, 465

    Login() Constants

     o LOGIN_CRAM_MD5
    Login using CRAM_MD5
     o LOGIN_CLEAR
    Login using clear text

    Instance Methods Index

     o Integer Close( )
    Close a connection to an SMTP server.
     o Integer Connect ( String host )
    Connect to an SMTP server.
     o String GetLastError()
    Retrieve the a string for the last error code.
     o Integer GetTimeout( )
    Returns the SMTP timeout in milliseconds.
     o Integer InitContext ( SSLOptions options )
    Used to initialize a security context for SecureLogin().
     o Integer Login( String username, String password, Integer loginMethod )
    Initiate a connection to an SMTP server.
     o Integer SecureLogin ( String hostname, String username, String password )
    Initiate a secure connection to an SMTP server.
     o Integer SendCommand( String command, String arguments )
    Sends raw SMTP commands.
     o Integer SendMessage( MailMessage message )
    Sends a mail message.
     o Integer SetTimeout( Integer timeout )
    Set SMTP timeout in milliseconds.

    Class Methods

     o New
     SMTPSession New( String host,
     		 Integer port )
            
    

    Returns a new SMTPSession object

    Parameters:
    host  -  IP address or domain name of SMTP host.
    port  -  SMTP connection port
    Returns:
    A new SMTPSession object or undefined if there was an error constructing the object.

    Instance Methods

     o Close
     Integer Close()
    

    No parameters. Closes the session.

    Parameters:
    None
    Returns:
    Returns 0 for success and -1 if an error occurred.
     o Connect
     Integer Connect(
    		 [String host] )
    

    The host parameter is optional and if not specified, will connect to the host as specified in the New() function. Otherwise, this host parameter will override whatever host param was used in the New() function. Use this if you do not require authentication to connect to your smtp server.

    Parameters:
    host  -  IP address or domain name of SMTP server.
    Returns:
    Returns 0 for success and -1 if an error occurred.
     o GetLastError
     String GetLastError( )
    

    No parameters. Returns an error string for the last error that occured.

    Parameters:
    None.
    Returns:
    Returns an error string for the last error that occured.
     o GetTimeout
     Integer GetTimeout()
    

    Gets the timeout value for SMTP commands. The timeout is in milliseconds.

    Parameters:
    None
    Returns:
    Returns the timeout in milliseconds, -1 if an error occured.
     o InitContext
     Integer InitContext(
                  SSLOptions options )
    

    Sets the SSL options for a secure connection. You must call this before attempting to do a SecureLogin() call.

    Parameters:
    options  -  an instance of SSLOptions.
    Returns:
    Returns 0 for success and -1 if an error occurred.
     o Login
     Integer Login(
                  String username,
                  String password,
                  [Integer loginMethod] )
    

    This function allows authenticated login to an smtp server, with two different methods available, LOGIN_CRAM_MD5 and LOGIN_CLEAR. The loginMethod param is optional and the default is LOGIN_CLEAR.

    Parameters:
    username  -  username used to login to SMTP server.
    password  -  password used to login to SMTP server.
    loginMethod  -  type of login authentication to use.
    Returns:
    Returns 0 for success and -1 if an error occurred.
     o SecureLogin
     Integer SecureLogin(
                  String hostname,
                  [String username,
                  String password] )
    

    The username/password parameters are optional, use them if your server also requires authentication as well as TLS/SSL. You must have called InitContext() before this.

    Parameters:
    hostname  -  IP address or domain name of SMTP server.
    username  -  user login on SMTP server
    password  -  user password for SMTP server
    Returns:
    Returns 0 for success and -1 if an error occurred.
     o SendCommand
     Integer SendCommand(
                  String command,
                  [String arguments] )
    

    Use this to send other raw SMTP commands. The arguments param is optional.

    Parameters:
    command  -  command to send
    arguments  - 
    Returns:
    Returns 0 for success and -1 if an error occurred.
     o SendMessage
     Integer SendMessage(
                  MailMessage message )
    

    Sends a previously created MailMessage ( an email ).

    Parameters:
    message  -  MailMessage to send
    Returns:
    Returns 0 for success and -1 if an error occurred.
     o SetTimeout
     Integer SetTimeout(
                  Integer timeout )
    

    Sets the timeout value for SMTP commands. The timeout is in milliseconds.

    Parameters:
    timeout  -  timeout in milliseconds.
    Returns:
    Returns 0 for success and -1 if an error occurred.