Sending Email

There are two ways to send email using CDO for Windows 2000. One method is to send messages to an email server using the SMTP protocol. The other method is to write messages to disk, where they are picked up by Microsoft’s SMTP system service. This section describes each method.

Sending Email via SMTP

CDO for Windows 2000 is able to talk directly to an SMTP email server. This can be Microsoft’s SMTP service or an email server located at your ISP. Example 12-1 shows a subroutine that sends a plain-text email message using this method.

Example 12-1. Sending Email Via SMTP

Private Sub SendMessage( ) Dim Cdo2Configuration As CDO.Configuration Dim Cdo2Fields As ADODB.Fields Dim Cdo2Message As CDO.Message ' Create a new Configuration object. Set Cdo2Configuration = New CDO.Configuration ' Get a reference to the Configuration object's Fields collection Set Cdo2Fields = Cdo2Configuration.Fields ' Set the Configuration object's properties through its Fields ' collection. With Cdo2Fields .Item(cdoSMTPServer) = "yourmailserver.com" .Item(cdoSendUsingMethod) = cdoSendUsingPort .Update ' Important End With ' Create a new message. Set Cdo2Message = New CDO.Message ' Set the message's configuration. Set Cdo2Message.Configuration = Cdo2Configuration ' Set the message content. Cdo2Message.Subject = "This is the message subject." Cdo2Message.TextBody = "This is the message text." ' Address the message. Cdo2Message.From = "jane@mycompany.com" Cdo2Message.To = "john@yourcompany.com" ...

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.