Python - 通过Outlook 2007/2010和win32com发送HTML格式的电子邮件 [英] Python - Send HTML-formatted email via Outlook 2007/2010 and win32com

查看:4492
本文介绍了Python - 通过Outlook 2007/2010和win32com发送HTML格式的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用Python的win32com.client(使用Outlook 2007/2010)发送HTML格式的电子邮件。我现在使用的格式如下所示:

Is there a way to send HTML-formatted email using Python's win32com.client (which utilizes Outlook 2007/2010). The format I'm using now looks like this:

import win32com.client
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "the subject"
newMail.Body = "body text"
newMail.To = "recipient@example.com"
attachment1 = "c:\\mypic.jpg"
newMail.Attachments.Add(attachment1)
newMail.Send()

这将使用Outlook发送一封电子邮件,从当前已认证的用户发送到指定的收件人,主题,内容和附加图片。

This will send an email using Outlook, sent from the currently authenticated user, to the specified recipient, with a subject, content, and attached image.

我想要发送一个内联图像,可以使用嵌入附件实现,或简单地链接到和使用HTML的图像,或使用HTML和Base64编码的图像嵌入图像。

I want to be able to send an inline image, which can be achieved using an "Embedded" attachment, or simply to link to and image using HTML, or embed an image using HTML and a Base64-encoded image.

HTML是我的首选方法,但是添加到正文中的任何HTML格式化为纯文本(例如 成为& lt; )。有没有办法告诉Outlook的身体内容是HTML,应该被解析为这样?

HTML is my preferred approach, but any HTML I add to the body is formatted and encoded as plain text (e.g. < becomes &lt;). Is there a way to tell Outlook the body content is HTML and should be parsed as such?

推荐答案

这是做的方式身体以html格式

This is the way to make the body in html format

newMail.HTMLBody  = htmltext

这篇关于Python - 通过Outlook 2007/2010和win32com发送HTML格式的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆