Keeping default outlook format when creating a new html e-mail

倖福魔咒の 提交于 2019-12-24 08:59:40

问题


I am trying to create a simple script to create a html message, and I would like to keep as much as possible of the default values.

In my case when I create a new message using Home -> New mail it would always create a mail with default font [Calibri 11'], format text Html, and also with a signature.

If I use the function Application.CreateItem(olMailItem) it creates the mail without issues.

However as soon as I declare an html body with .HTMLBody it will overwrite the format: font [Times New Roman 12'], and also without a signature.

Even more surprising: if I use the 'trick' found online to keep the signature (see code bellow) then the font would be then overwritten to [Calibri 10'] (one point bellow the default)

Any recommendation/explanation?

Simple script to create an html mail (change of font + no signature) :

Sub TestMessage1()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
    .To = "test@domain"
    .Subject = "test Mail"
    .HTMLBody = "<p>Hello,<br><br>Could you please review this program<br><br>Regards,</p>"
    .Display
End With
End Sub

write html mail with a signature (different change of font):

Sub TestMessage2()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
With objMsg
    .To = "test@domain"
    .Subject = "test Mail"
    .Display
    .HTMLBody = "<p>Hello,<br><br>Could you please review this program<br><br>Regards,</p>" & objMsg.HTMLBody
End With
End Sub

回答1:


You need to paste the text or well-formatted HTML markup right after the <body> tag and before the closing </body> tag. In that case all format preferences will be preserved.



来源:https://stackoverflow.com/questions/43869628/keeping-default-outlook-format-when-creating-a-new-html-e-mail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!