使用cdo.message发送电子邮件时指定我自己的message-id标头

时间:2016-11-17 17:01:39

标签: asp-classic cdo.message

有没有办法用CDO指定我自己的message-id?

使用以下配置,仍然会由cdo组件生成message-id,并忽略我指定的那个。

<%
Const cdoSendUsingPort = 2

Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

' set the CDOSYS configuration fields to use port 25 on the SMTP server
With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp@example.com"

    .Item("urn:schemas:mailheader:message-id") = "0123456789.0123456789@example.com"
.Update
End With

With iMsg
    Set .Configuration = iConf

    .From = "from@example.com"
    .Subject = "test"
    .To = "to@example.com"
    .HTMLBody = "test"
    .Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
%>

1 个答案:

答案 0 :(得分:2)

配置对象iConf与消息对象iMsg无关, 你不需要创建它。

因此,请移除Set iConf = CreateObject("CDO.Configuration")并将Set Flds = iConf.Fields替换为Set Flds = iMsg.Fields

您需要使用iMsg.Fields为邮件设置标题。

Setting Message Header Fields

Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set Flds = iMsg.Fields
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

' set the CDOSYS configuration fields to use port 25 on the SMTP server
With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.example.com"
    .Update
End With

With iMsg.Fields
    .Item("urn:schemas:mailheader:message-id") = "0123456789.0123456789@example.com"
    .Update
End With

With iMsg
    Set .Configuration = iConf

    .From = "from@example.com"
    .Subject = "test"
    .To = "to@example.com"
    .HTMLBody = "test"
    .Send
End With