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

查看:38
本文介绍了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?

推荐答案

这是把body做成html格式的方法

This is the way to make the body in html format

newMail.HTMLBody  = htmltext

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

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