2

Is there a way to specifty my own message-id with CDO ?

Using the following configuration, the message-id is still generated by the cdo component and ignores the one I specified.

<%
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
%>
Jonathan
  • 1,276
  • 10
  • 35

1 Answers1

3

The configuration object iConf is irrelevant to the message object iMsg, you don't need to create it.

So, remove Set iConf = CreateObject("CDO.Configuration") and replace Set Flds = iConf.Fields with Set Flds = iMsg.Fields.

You need to use iMsg.Fields to set headers for the message.

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
Kul-Tigin
  • 16,728
  • 1
  • 35
  • 64
  • I updated my code example to show what I do later with iConf (put in iMsg.Configuration). If I try not using it like you suggest I get an error: "The "SendUsing" configuration value is invalid." – Jonathan Nov 17 '16 at 21:19
  • 1
    got it working, I needed to set sendusing and smtpserver configuration in iMsg.Configuration.Fields instead of iMsg.Fields. I receive my message-id now, please update your code solution and I'll mark your answer as the solution – Jonathan Nov 17 '16 at 21:28
  • @Jonathan you're right, updated the answer. – Kul-Tigin Nov 17 '16 at 21:38
  • You've [already answered this](http://stackoverflow.com/a/19184371/692942) previously. – user692942 Nov 17 '16 at 22:11
  • @Lankymart I beleive I can find another one. – Kul-Tigin Nov 17 '16 at 22:30
  • I found that I needed to put enclosing chevrons in the value: `.Item("urn:schemas:mailheader:message-id") = "<0123456789.0123456789@example.com>"` – user2192333 Feb 26 '20 at 17:47