One of my most popular posts is my function for sending e-mail using Outlook automation: VBA – Send HTML Emails Using Outlook Automation. That said, there is an issue with that code, the way I retain the signature in the generate e-mail.
The Problem With Concatenation of .HTMLBody
Although this is the most common approach seen online (from what I have seen over the years); to concatenate the message we want to send with the existing body when the e-mail is first created:
.HTMLBody = sMyHTMLMessage & .HTMLBody
The issue being that .HTMLBody will already be a complete HTML document
<html ...>
<head>...</head>
<body ...>
...
</body>
</html>
and the concatenation is prepending the user’s message at the beginning, outside the html/body tags, resulting in
The User's Message is prepended here!
<html ...>
<head>...</head>
<body ...>
...
</body>
</html>
which is simply incorrect HTML!
Now, some e-mail clients, such as Outlook, deal with this just fine, but this can cause issue for others. As such, I wanted to find a way to generate an HTML e-mail while creating proper HTML.
Continue reading →