2

I am attempting to generate some emails using VBScript CDO.Message, code is below.

The receiving clients, IBM (Lotus) Notes, require a number of pieces of information supplied using one header "X-Notes-Item" repeated many times.

i.e.

[..snip..]
From: [from@hidden].com
X-Notes-Item: value 1; name=Key1
X-Notes-Item: value 2; name=Key2
X-Notes-Item: value 3; name=Key3
MIME-Version: 1.0
Content-type: text/html; charset=UTF-8
[..snip..]

But it seems the script is setting the header once and then just overwriting it repeatedly so only the final value for X-Notes-Item is sent.

Option Explicit

Dim objMessage, objShell

Set objShell = CreateObject("wscript.Shell")
Set objMessage = CreateObject("CDO.Message")

With objMessage
    .Subject = "[Blah]"
    .From = "[from@hidden].com"
    .Sender = "[sender@hidden].com"
    .To = "[to@hidden].com"
    .Fields("urn:schemas:mailheader:X-Notes-Item") = "value 1; name=Key1"
    .Fields("urn:schemas:mailheader:X-Notes-Item") = "value 2; name=Key2"
    .Fields("urn:schemas:mailheader:X-Notes-Item") = "value 3; name=Key3"
    .Fields.Update

    .HTMLBody = "<html><body><p>[Blah]</p></body></html>"

    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "PWNOTSMTP"
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Configuration.Fields.Update
    .Send
End With

Set objMessage=Nothing

I have also tried using a list, got an error

Fields update failed. For further information, examine the Status property of individual field objects.

but I'm not at all well versed in VBScript so no idea if this is even close to correct implementation or if it would never work either way?

'...
Dim list
Set list = CreateObject("System.Collections.ArrayList")
list.Add "value 1; name=Key1"
list.Add "value 2; name=Key2"
list.Add "value 3; name=Key3"

With objMessage
    '...
    .Fields("urn:schemas:mailheader:X-Notes-Item") = list
    .Fields.Update
    '...
End With
'...

Also, clutching at straws, I tried adding a .Fields.Update between each header line, which predictably made no difference

Is there a simple way that I'm totally missing to add a set of repeated headers?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
antwebb
  • 21
  • 3

0 Answers0