Sending email using CDO & remote SMTP Server


Assume that the computer on which this example will run has neither a SMTP service nor Microsoft Outlook® Express installed. In this case, you need to send the message through some SMTP service on the network and must configure the Message object completely.


Further assume that the SMTP service through which you intend to send messages requires that you authenticate yourself using basic (clear-text) authentication. An instance of the Configuration Component Object Model (COM) class is created and the configuration fields in the object are set with values such as the required SMTP server name, port, authentication, and user name and password.


Each field is in the http://schemas.microsoft.com/cdo/configuration/ namespace. As you know the http://schemas.microsoft.com/cdo/configuration/ namespace defines the majority of fields used to set configurations for various CDO objects. These configuration fields are set using an implementation of the IConfiguration.Fields collection.


Many CDO objects use information stored in an associated Configuration object to define configuration settings. One example is the Message object, where you use its associated Configuration object to set fields such as sendusing. This field defines whether to send the message using the local SMTP service drop directory (if the local machine has the SMTP service installed), an SMTP service directly over the network. If sending over the network, you set smtpserver to specify the IP address or DNS name of the machine hosting the SMTP service, and optionally, smtpserverport to specify a port value. If credentials are required for connecting to an SMTP service, you can specify them by setting the sendusername and sendpassword.


A similar set of fields exists for posting messages using either a local NNTP service pickup directory, or over the network After the Configuration object has been populated with relevant configuration information, the object reference is set on a Message object. The Message object uses the configuration information to send the message. Here as stated below the fully qualified field names are used to clarify the process. However, there are string constants (as type library modules) in the type library for each of these field names.





I have enclosed the SMTP configuration parameters for your reference:

   1:  Flds("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "sample.smtp.com"
   2:  Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
   3:  Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
   4:  'CdoSendUsing enum value =  2
   5:  Flds("http://schemas.microsoft.com/cdo/configuration/smtpaccountname") = "My Name"
   6:  Flds("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = """MySelf"" <myself@example.com>"
   7:  Flds("http://schemas.microsoft.com/cdo/configuration/senduserreplyemailaddress") = """Another"" <another@example.com>"
   8:  Flds("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
   9:  Flds("http://schemas.microsoft.com/cdo/configuration/sendusername") = "domain\username"
  10:  Flds("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"


Skip to main content