Search code examples
emaillotus-dominolotusscriptmime-message

Multiple To and Cc headers in MIME message sent through LotusScript


I'm building a LotusScript agent looping through a set of documents then - based on a given condition - create mail messages with formatted html text. The recipients will be mostly Non-Notes users (Outlook etc) that's why I want to make sure that subject and message body are formatted correctly. At least one copy is sent to a Domino mail-in database, though.

The code basically creates a MimeEntity, sets "To", "CC" and "Subject" headers then puts a pre-configured message into the mail body and sends it off.

In regards to the body I experimented both with a simple MimeEntity formatted as "text/html" as well as with a multipart message (Content-Type = "multipart/alternative") with 2 child entities (1: "text/plain" without any formatting, 2: "text/html" i.e. html-formatted); in my final code I plan to go for the latter method.

What is really weird is that the recipients (using Outlook as well as other mail clients like Thunderbird) see 3 "To:" and 3 "Cc:" items instead of just one. Looking at the doc in the receiving Domino mail-in database there is only one instance of each item (i.e. SendTo and CopyTo).

Here's the message's source code (taken from Thunderbird) showing those 3 instances of each item:

Return-Path: <[email protected]>
Received: (removed info here)
Subject: =?UTF-8?B?RWluIGdlbcO8dGxpY2hlcyBzaW1wbGVzIFRlc3RtYWlsIGF1cyBTT1A=?=
MIME-Version: 1.0
Auto-Submitted: auto-generated
To: [email protected], [email protected]
CC: [email protected]
To: [email protected], [email protected]
CC: [email protected]
To: [email protected], [email protected]
CC: [email protected]
Message-ID: <OFBCA50979.C1582837-ONC125856E.00548385-C125856E.0054838A@MYORG.DE>
From: Lothar Mueller <[email protected]>

This the basic code creating these mails (the simple non-multipart version):

Set docMemo = db.Createdocument()
Call docMemo.Replaceitemvalue("Form", "Memo")
Set nMimeBody = docMemo.Createmimeentity()

'SendTo
Set nMimeHead = nMimeBody.Createheader("To")
Call nMimeHead.Setheaderval("[email protected],[email protected]")

'CopyTo
Set nMimeHead = nMimeBody.Createheader("CC")
Call nMimeHead.Setheaderval("my-mail-in-db")

'Subject
Set nMimeHead = nMimeBody.Createheader("Subject")
Call nMimeHead.Addvaltext("Subject with ä-ö-ü-ß", "UTF-8")

'html version only for simple non-multipart MIME
Call nStream.Writetext({<p style="font-weight:bold;">Some simple formatted HTML content</p>})
Call nMimeBody.Setcontentfromtext(nStream, {text/html; charset="UTF-8"}, ENC_NONE)
Call nStream.Close()

'finally send
Call docMemo.Send(False)

Now, I can work around this behavior by simply setting the recipients as plain old Notes items, like:

Call docMemo.SendTo = recipientArray
Call docMemo.CopyTo = copyArray

instead of setting those values as MIME headers. In this case there are no more multiple instances of "To" and "CC" items at the recipients' mail clients.

I know that I did this already some years ago in a different project, and back then I didn't have those problems.

Anyone having an idea what could be the cause for this? Could it be due to the Domino version in use (now it's 10.0.1 FP4, back then it was some 9.0.1 version)?


Solution

  • Guess I found the cause for this, at least partially:

    As I mentioned in an update to my post this behavior only can be observed when the agent is running in the client as opposed to running on the server:

    examining the resulting mail through Ytria's scanEZ I find that there's a difference in regards to the fields that are created:

    1. the run-on-server version just creates the expected fields "To:" and "Cc:" which turn up as "SendTo" and "CopyTo" in the resulting Notes document
    2. If the code is running in the client some more fields are created in the Notes document: in addition to the standard fields there are also "INetSendTo", INetCopyTo, "AltSendTo" and "AltCopyTo". I assume that those extra fields are then rendered by the router to become addition "To:" and "Cc:" header items.

    Thanks again to @DaveDelay for bringing up that idea regarding the router and mail.box