How do I use CDO with Exchange with vbscript

Francis Fetsch picture Francis Fetsch · Jun 8, 2011 · Viewed 17.4k times · Source

I am trying to setup a script to email using an exchange account. I want to use CDO (or equivalent) with vbscript. The goal is to track email communications through the sent folder of the exchange account. I am using exchange 2007.

Answer

NeerPatel picture NeerPatel · Jun 9, 2011

Use Microsoft NTLM (http://msdn.microsoft.com/en-us/library/aa378749(v=vs.85).aspx) In CDO it's a CdoProtocolsAuthentication Enum (http://msdn.microsoft.com/en-us/library/ms526961(v=exchg.10).aspx)

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

dim objEmail
    Set objEmail = CreateObject("CDO.Message") 
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")= cdoSendUsingPort 
'Name or IP of remote SMTP server
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="exchange"
'Server port
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =25 

objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpAuthenticate") = cdoNTLM 
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/NNTPAccountName") = "USERNAME"
 objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/SaveSentItems") = TRUE

objEmail.Configuration.Fields.Update
objEmail.From = "FROM <[email protected]>"
    objEmail.To = "[email protected]"
    objEmail.Subject = "SUBJECT"
    objEmail.Textbody = "BODY " 
    objEmail.Send