vbscriptexchange-serverexchange-server-2007cdo.message

How do I use CDO with Exchange with vbscript


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.


Solution

  • 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 <FROM@domain.com>"
        objEmail.To = "TO@domain.com"
        objEmail.Subject = "SUBJECT"
        objEmail.Textbody = "BODY " 
        objEmail.Send