Class CdoMessageHelper
VBScript Library: net\CdoMessageHelper.vbs

Wrapper around CDO to pre-configure CDO.Message objects with connection and configuration details.

By configuring a single CdoMessageHelper instance, you can make repeated calls to getNewMessage() to quickly obtain pre-configured CDO.Message objects.

Reference

Method Detail

Return Type Method and Description
Int getAuthType()
Returns the type of authentication that will be used.

Returns: One of SMTP_AUTH_TYPE_BASIC, SMTP_AUTH_TYPE_NONE or SMTP_AUTH_TYPE_NTLM.

CDO.Message getNewMessage(byVal sendFrom, byVal sendTo, byVal subject, byVal body)
Creates a new CDO.Message instance and sets the configuration, from, to and subject.

To specify a name in the sendFrom address use the format: John Smith <jsmith@example.com>

Parameters:

  • sendFrom (String): the sending e-mail address
  • sendTo (String): the recipients of the e-mail, separated by ;
  • subject (String): the subject line for the e-mail
  • body (String): the body text for the e-mail

Returns: a new CDO.Message instance with the configuration, connection and message details pre-set.

String getPassword()
Returns the password that was set with setCredentials().

Returns: the password that was set with setCredentials()

Int getPort()
Returns the port this CdoMessageHelper will connect on.

Returns: the port number this instance will connect on

String getServer()
Returns the server this CdoMessageHelper instance will configure CDO.Message objects to connect to.

Returns: the server this CdoMessageHelper instance will configure CDO.Message objects to connect to

String getUsername()
Returns the username that was set with setCredentials().

Returns: the username that was set with setCredentials()

- setAuthType(byVal authType)
Sets the type of authentication that will be used.

Parameters:

  • authType (Int): must be one of SMTP_AUTH_TYPE_BASIC, SMTP_AUTH_TYPE_NONE or SMTP_AUTH_TYPE_NTLM
- setCredentials(byVal username, byVal password)
Sets the credentials that will be used to authenticate.

Parameters:

  • username (String): the username to authenticate with
  • password (String): the password to authenticate with
- setPort(byVal port)
Sets the port to connect on.

Parameters:

  • port (Int): the port to connect on, must be between 1 and 65,535 (inclusive)
- setServer(byVal server)
Sets the server (hostname or IP) to connect to.

Parameters:

  • server (String): the hostname or IP address to connect to
- setUseSsl(byVal useSsl)
Sets whether CDO.Message objects should use SSL.

Parameters:

  • useSsl (Bool): true to use SSL
Bool useSsl()
Returns true if SSL will be used on CDO.Message objects.

Returns: true if SSL will be used on CDO.Message objects

Script Constants

Name Type Value Description
SMTP_AUTH_TYPE_BASIC Int 1 Use with setAuthType() to use basic authentication.
SMTP_AUTH_TYPE_NONE Int 0 Use with setAuthType() to disable authentication.
SMTP_AUTH_TYPE_NTLM Int 2 Use with setAuthType() to use NTLM authentication.
SMTP_PORT_DEFAULT Int 25 Default port for unencrypted SMTP traffic.
SMTP_PORT_SSL Int 465 Default port for SSL encrypted SMTP traffic.
SMTP_SCHEMA_AUTH String - CDO schema to control configuration settings, used internally.
Value: http://schemas.microsoft.com/cdo/configuration/smtpauthenticate
SMTP_SCHEMA_HOST String - CDO schema to control configuration settings, used internally.
Value: http://schemas.microsoft.com/cdo/configuration/smtpserver
SMTP_SCHEMA_PASS String - CDO schema to control configuration settings, used internally.
Value: http://schemas.microsoft.com/cdo/configuration/sendpassword
SMTP_SCHEMA_PORT String - CDO schema to control configuration settings, used internally.
Value: http://schemas.microsoft.com/cdo/configuration/smtpserverport
SMTP_SCHEMA_SENDUSING String - CDO schema to control configuration settings, used internally.
Value: http://schemas.microsoft.com/cdo/configuration/sendusing
SMTP_SCHEMA_SSL String - CDO schema to control configuration settings, used internally.
Value: http://schemas.microsoft.com/cdo/configuration/smtpusessl
SMTP_SCHEMA_USER String - CDO schema to control configuration settings, used internally.
Value: http://schemas.microsoft.com/cdo/configuration/sendusername

Sample Usage

Option Explicit

Dim msgHelper: Set msgHelper = new CdoMessageHelper
msgHelper.setServer "smtp.gmail.com"
msgHelper.setCredentials "username@example.com", "password"
msgHelper.setUseSsl True

Dim cdoMsg: Set cdoMsg = msgHelper.getNewMessage( _
        "Your Name <youremail@example.com>", _
        "recipient1@example.com", _
        "Hello, this is the subject", _
        "Hello, this is the message body." )
cdoMsg.send