Outook Attach .docx - 作为文本插入

时间:2018-02-03 00:56:07

标签: python email outlook attachment

我正在尝试发送一封附件作为电子邮件正文的电子邮件。我想复制附件 - >插入作为文本选项,您可以在实际的Outlook应用程序中使用。

这是我尝试的代码,但无法将我的文档作为文本插入电子邮件正文中。

import win32com.client

#some constants (from http://msdn.microsoft.com/en-us/library/office/aa219371%28v=office.11%29.aspx)
olFormatHTML = 2
olFormatPlain = 1
olFormatRichText = 3
olFormatUnspecified = 0
olMailItem = 0x0

obj = win32com.client.Dispatch("Outlook.Application")

attachment1 = "test.docx"

with open(attachment1 , 'r') as myfile:
    data=(myfile.read())

newMail = obj.CreateItem(olMailItem)
newMail.Subject = "I AM SUBJECT!!"
newMail.BodyFormat = olFormatHTML    #or olFormatRichText or olFormatPlain
newMail.HTMLBody = data
newMail.To = "help@example.com"


newMail.Attachments.Add(Source=attachment1)

# open up in a new window and allow review before send
newMail.Display()

0 个答案:

没有答案