超出附件。docxInsert为Tex

2024-10-01 17:21:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图发送一封电子邮件与附件作为电子邮件正文。我想复制可以在实际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()

Tags: 文本comclientobj电子邮件openmyfilewin32com

热门问题