[英]Python win32com outlook attach file with “insert as text” method
I am trying to send a HTML webpage via outlook with python win32com. 我正在尝试使用python win32com通过Outlook发送HTML网页。 However, I don't know how to config the add attachment call to do "insert as text" method. 但是,我不知道如何配置添加附件调用来执行“插入为文本”方法。
Does anyone know how to do that? 有谁知道这是怎么做到的吗?
import win32com.client
from win32com.client import Dispatch, constants
const=win32com.client.constants
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "I AM SUBJECT!!"
newMail.Body = "I AM IN THE BODY\nSO AM I!!!"
newMail.To = "abc@abc.com"
attachment1 = "x:\\report.htm"
newMail.Attachments.Add(Source=attachment1)
newMail.display()
newMail.Send()
thank you very much. 非常感谢你。
you can use this 你可以用这个
import win32com.client
from win32com.client import Dispatch, constants
const=win32com.client.constants
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "I AM SUBJECT!!"
newMail.To = "abc@abc.com"
attachment1 = "x:\\report.htm"
with open(attachment1 , 'r') as myfile:
data=myfile.read()
newMail.Body = "Please Find the Report here " + data
newMail.HTMLBody = "I AM IN THE BODY\nSO AM I!!!" + data
newMail.Attachments.Add(Source=attachment1)
newMail.display()
newMail.Send()
you may need to convert the html file to string first and concatenate with mail.body 您可能需要先将html文件转换为字符串并与mail.body连接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.