View Full Version : How to use CDO to send email with external server with Authentication

February 3rd, 2011, 11:37 AM
Recently a customer needed to use an external mail server to send email from a web page, using Authentication on the mail server. Here is some code that worked for that:

Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item(cdoSendUsingMethod) = 2 'cdoSendUsingPort
.Item(cdoSMTPServer) = "name_of_server.com"
.Item(cdoSMTPAuthenticate) = 1
.Item(cdoSendUsername) = "username"
.Item(cdoSendPassword) = "password"
End With

Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
Set .Configuration = cdoConfig
.From = "[email protected]_address.com"
.To = "[email protected]_address.com"
.Subject = "This is the subject of the email"
.TextBody = "This is a test for CDO.message with authentication"
End With

Set cdoMessage = Nothing
Set cdoConfig = Nothing