I am trying to send a Rich Text Format email message using Outlook 2003. The following code results the RTF HTML source code to be dumped into the mail message body.
What should I do in order to fix that, and make Outlook display the formatted data and not the source HTML ?
import win32com.client
RTFTEMPLATE = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
08.00.0681.000">
<TITLE>%s</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P DIR=3DLTR><SPAN LANG=3D"en-us"><FONT =
FACE=3D"Calibri">%s</FONT></SPAN><SPAN =
LANG=3D"en-us"></SPAN></P>
</BODY>
</HTML>"""
Format = { 'UNSPECIFIED' : 0, 'PLAIN' : 1, 'HTML' : 2, 'RTF' : 3}
profile = "Outlook"
subject="Subject"
body = "Test Message"
session = win32com.client.Dispatch("Mapi.Session")
outlook = win32com.client.Dispatch("Outlook.Application")
session.Logon(profile)
mainMsg = outlook.CreateItem(0)
mainMsg.To = "[email protected]"
mainMsg.Subject = subject
mainMsg.BodyFormat = Format['RTF']
mainMsg.Body = RTFTEMPLATE % (subject,body)
mainMsg.Send()
EDIT: When using HTMLBody instead of Body, Outlook detects the message as HTML and not as RTF.