Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm working with a web app in VB ASP 3.0. I have the following code to send an email:

    Const cdoSendUsingMethod        = _
            "http://schemas.microsoft.com/cdo/configuration/sendusing"
    Const cdoSendUsingPort          = 2
    Const cdoSMTPServer             = _
            "http://schemas.microsoft.com/cdo/configuration/smtpserver"
    Const cdoSMTPServerPort         = _
            "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
    Const cdoSMTPConnectionTimeout  = _
            "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
    Const cdoSMTPAuthenticate       = _
            "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
    Const cdoBasic                  = 1
    Const cdoSendUserName           = _
            "http://schemas.microsoft.com/cdo/configuration/sendusername"
    Const cdoSendPassword           = _
            "http://schemas.microsoft.com/cdo/configuration/sendpassword"

    Set objMessage = CreateObject("CDO.Message")
        objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 
        objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1 
        objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="xxxxxxx"
        objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="xxxxxxx" 
        objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=false 
        objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.socketlabs.com"

        objMessage.Configuration.Fields.Update 

    fFromEmail = "xxx@xxx.com"
    fFromAlias = "Display name"
    fReplyTo = "xxx@xxx.com"
    if isObject(objMessage) then
        With objMessage
            .To       = fToEmail
            .Cc      = fCCEmail
            .Bcc      = fBCCEmail
            .From     = fFromAlias & "<" & fFromEmail & ">"
            .Subject  = fSubject
            .HTMLBody = fEmailBody
            .Send
        End With

        SendEmail = summaryEmailBody
        Set objMessage = Nothing
    End If

This script works, but now I need to add an extra header. But I can't find how to do so when not in a .net framework.

I tried adding the following line:

        objMessage.Configuration.Fields.Item("urn:schemas:mailheader:X-xsMailingId") = "clientName"

but it didn't work. Any help will be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
554 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to add the header into the objMessage.Fields collection instead of objMessage.Configuration.Fields according to official documentation (see VBScript section)

objMessage.Fields.Item("urn:schemas:mailheader:X-xsMailingId") = "clientName"
objMessage.Fields.Update

Then it should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...