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 ..." oMessage.Save End Sub
Code: Select all
Return-Path: email@example.com Delivered-To: firstname.lastname@example.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 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 <email@example.com> Subject: Test: Set headers in OnSMTPData event To: "Doe, Jon" <firstname.lastname@example.org> Message-ID: <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 Thunderbird/18.104.22.16858b MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit This is the real body
Ironically, the header originally set in OnSMTPData is missing