添加额外的标题到电子邮件VB ASP 3.0脚本

时间:2013-10-04 14:00:34

标签: email vbscript

我正在使用VB ASP 3.0中的Web应用程序。我有以下代码发送电子邮件:

    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

此脚本有效,但现在我需要添加额外的标头。但是当我不在.net框架中时,我找不到如何做到这一点。

我尝试添加以下行:

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

但它不起作用。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:4)

您需要根据official documentation将标头添加到objMessage.Fields集合而不是objMessage.Configuration.Fields(请参阅VBScript部分)

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

然后它应该工作。

答案 1 :(得分:0)

工作版本示例:

queueMail_Count = queueMail_Count+1
queueMail_errorLine_1 = (rsMailQueue.Fields.Item("UIC").Value)
queueMail_errorLine_2 = (rsMailQueue.Fields.Item("email").Value)
queueMail_errorLine_3 = (rsMailQueue.Fields.Item("queue_TrackingNumber").Value)
queueMail_errorLine_4 = (queueMail_Count)

Set queueMail=CreateObject("CDO.Message")     queueMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
queueMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
queueMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25     queueMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
queueMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="postmaster@site.com"
queueMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="########"
queueMail.Configuration.Fields.Update
queueMail.Fields.Item("urn:schemas:mailheader:X-Mailgun-Campaign-Id")="omaha_valley"
queueMail.Fields.Item("urn:schemas:mailheader:X-Mailgun-Track")="yes"
queueMail.Fields.Update

queueMail.Subject=rsQueue.Fields.Item("subjectLine").Value
queueMail.From="""" & (issueEditorFrom) & """ <" & (issueEditorFromEmail) & ">"
queueMail.To=(rsMailQueue.Fields.Item("email").Value)
queueMail.CreateMHTMLBody "" & (pageToSend) & ""
queueMail.Send