سؤال

Using win32com.client package, I'm able to send an HTML email using outlook through Python. However, I'm having a hard time figuring out how to mark an email "high priority" or "high importance".

Here is the code I'm using to successfully send out an email (with no priority marking):

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="Times New Roman">
%s
</FONT></SPAN><SPAN =
LANG=3D"en-us"></SPAN></P>
<br>
%s
</BODY>
</HTML>"""

Format = { 'UNSPECIFIED' : 0, 'PLAIN' : 1, 'HTML' : 2, 'RTF'  : 3}
profile = "Outlook"


#session = win32com.client.Dispatch("Mapi.Session")
outlook = win32com.client.Dispatch("Outlook.Application")
#session.Logon(profile)
mainMsg = outlook.CreateItem(0)
mainMsg.To = "RECIPIENT"
mainMsg.Subject = subject
mainMsg.BodyFormat = Format['RTF']
mainMsg.HTMLBody = RTFTEMPLATE % (subject,html,bad_table)
mainMsg.Send()
هل كانت مفيدة؟

المحلول

You are creating your message through the COM Outlook Object Model. This model is fully documented, which can be a great help in situations like this.

For instance, the MailItem you are creating is documented here. As you can tell from that page, it has a property Importance which you can set to 2 (olImportanceHigh) to mark the message as "high importance".

In code

mainMsg.Importance = 2

نصائح أخرى

To mark a message so that it's recognized as 'high priority' by Outlook, add the following line to the message headers:

X-Priority: 1

But, I couldn't tell you how to add lines to the message headers by way the component that you are using.

Try setting these additional headers;

X-Priority: 1 (Highest)
X-MSMail-Priority: High
Importance: High

See e.g. http://www.chilkatsoft.com/p/p_471.asp for code examples and discussion.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top