如下图,目前我已经实现了使用 Outlook 2010 和 python 发送 HTML 格式的邮件
def send_mail_via_com(self):
o = win32com.client.Dispatch("Outlook.Application")
Msg = o.CreateItem(0)
Msg.To = self.myEmailAddress
Msg.BCC = self.myEmailAddress
Msg.Subject = 'This is Subject'
Msg.HTMLBody = htmlEmailContent
Msg.Send()
展望未来,我想在 HTML 格式的电子邮件中显示一些嵌入图像,我检查了 HTML 源代码,如下所示:
<img border=0 width=117 height=20 id="Picture_x0020_2" src="cid:image001.png@01CE9386.AB9B5E70" alt="Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: cid:786FB7C2-A5F6-462A-B0FD-EA865CD02221@xxx.example.com">
我尝试附加图像文件(使用上述 html 代码中引用的相同名称作为附件),但它只是附件,不会作为嵌入图像显示在文本正文中。我们的邮件服务器不支持 SMTP 协议,所以我不能像Sending Multipart html emails which contains embedded images中那样使用 smtplib 。有人可以帮帮我吗?提前致谢!
attachment1 = "G:\\image001.png"
Msg.Attachments.Add(attachment1)
2013/8/8 更新,我通过http://social.msdn.microsoft.com/Forums/vstudio/en-US/6c063b27-7e8a-4963-ad5f-ce7e5ffb2c64/how-to-embed-获得了 C# 版本代码image-in-html-body-in-c-into-outlook-mail,谁能给我看一下这些的 Python 对应代码:
Attachment attachment = newMail.Attachments.Add(
@"E:\Pictures\image001.jpg"
, OlAttachmentType.olEmbeddeditem
, null
, "Some image display name"
);
string imageCid = "image001.jpg@123";
attachment.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E"
, imageCid
);
newMail.HTMLBody = String.Format(
"<body><img src=\"cid:{0}\"></body>"
, imageCid
);