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("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
iFields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailhost"
iFields.Update
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"
cdoObj.Send

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.

Comments

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?