[英]Python win32com.client send image embedded in email
I am looking to send an image embedded in HTML to send out to a list of senders. 我希望发送嵌入HTML的图像以发送到发件人列表。
I need to use win32com.client, SMTP is blocked. 我需要使用win32com.client,SMTP被阻止。 The image is saved as png and is originally a matplotlib bar chart.
图像另存为png,最初是matplotlib条形图。
The script successfully sends out the email the recipients cannot see the image embedded in the email. 该脚本成功发送了电子邮件,使收件人看不到电子邮件中嵌入的图像。 However, I can see the image when I send the email to myself.
但是,当我向自己发送电子邮件时,我可以看到图像。
I tried to attach the image to the email, still no luck. 我尝试将图像附加到电子邮件中,仍然没有运气。
email = """<body>
<p><img src="C:\output.png"></p>
</body>
"""
import win32com.client
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "the subject"
newMail.HTMLBody = email
newMail.To = "my_email@co.com;outside_email@co.com"
attachment1 = "C:\output.png"
newMail.Attachments.Add(attachment1)
newMail.Send()
Any help greatly appreciated! 任何帮助,不胜感激!
The distribution list and I have a shared drive . 通讯组列表和我有一个共享驱动器 。 I saved the file in the shared drive and now the receivers of the message can see the image in the email.
我将文件保存在共享驱动器中,现在邮件的收件人可以在电子邮件中看到该图像。
I had a similar issue, sending images through the body. 我有一个类似的问题,通过身体发送图像。 Below I have attached the code that fixed it for me.
下面,我附上了为我修复的代码。
Code: 码:
email.Display(False) ;
email.Send()
In order to display the image in the mail body, use the below code: 为了在邮件正文中显示图像,请使用以下代码:
mail.Attachments.Add(file_location + 'test.png')
mail.HTMLBody = "<html><body> <img src='cid:test.png'> </body></html>";
Basically if you want to display an attached image in the mail body, you have to refer to it using img src = 'cid:name'
, or else it won't be shown. 基本上,如果您想在邮件正文中显示附件图像,则必须使用
img src = 'cid:name'
来引用它,否则它将不会显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.