due to an scripting issue in our company with an huge business impact, I figured out what happens when email headers will be set in OnSMTPData event.
In event OnSMTPData the oMessage object provides only the sender and all recipients but no email headers or contents. When a header will be set at this early point, hMailserver will create a raw mail and dump some basic headers there, including an empty line at the end. When the transmission continues with the real headers and contents as a part of DATA command, all will be interpreted as body part, including the headers. The recipient will now see the email source instead of the email content. The email is not readable by user and attachments won't be downloadable!
Therefore setting headers in event OnSMTPData should rather fail and result a scripting error.
Code: Select all
Sub OnSMTPData(oClient, oMessage)
oMessage.HeaderValue("X-TestHeader") = "Testing headers in OnSMTPData which is a bad idea ..."
will result in:
Code: Select all
Content-Type: text/plain; charset="utf-8"
Date: Fri, 4 Aug 2017 17:39:19 +0200
Received: from [10.x.y.z] (client.test.lab [10.x.y.z])
by mx.test.lab with ESMTPSA
(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128)
; Fri, 4 Aug 2017 17:39:19 +0200
From: Jane Doe <firstname.lastname@example.org>
Subject: Test: Set headers in OnSMTPData event
To: "Doe, Jon" <email@example.com>
Date: Fri, 4 Aug 2017 17:39:17 +0200
User-Agent: Mozilla/6.1 (Windows NT 10.0; WOW64; rv:54b.0) Gecko/20100101
Content-Type: text/plain; charset=utf-8; format=flowed
This is the real body
The first 5 lines (including the empty line) will be set by event handler. All data afterwards will be interpreted as body.
Ironically, the header originally set in OnSMTPData is missing