HTML mail body content is garbled/distorted with CDO.Message object

This is a common thing that you might see when you are trying to create an automated mail using the CDO.Message object.

Set cdoObj = CreateObject("cdo.message")

Set iConf = CreateObject("CDO.Configuration")
Set iFields = iConf.Fields
iFields.Item("") = 2
iFields.Item("") = "mailhost"
Set cdoObj.Configuration = iConf
cdoObj.Subject =”Test Email”
cdoObj.CreateMHTMLBody "C:\temp\Temp.html"
cdoObj.To = "TO EMAIL ID"
cdoObj.From = "FROM EMAIL ID"
cdoObj.BodyPart.Charset = "utf-8"

Now once you automate and recieve the email , you will see that the HTML source of received email has “!” characters at different location due to which HTML Tags are affected.
Temporaray solution: “vbNewLine” before ever tag

Better solution:  Use .HTMLBodyPart.ContentTransferEncoding = "quoted-printable"
which will remove all references of ! within the text inside the table.


Popular posts from this blog

XPATH for IE / internet explorer

RPA - Blue Prism, OpenSpan, Automation Anywhere vs UIPath