简体   繁体   English

Python win32com.client发送电子邮件中嵌入的图像

[英]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.

相关问题 使用 Python Win32Com.Client 发送电子邮件发送错误 - Sending Email with Python Win32Com.Client Send Error 使用win32com.client向自己发送电子邮件 - Send myself an email using win32com.client 使用 python 库 win32com.client 在没有任何许可的情况下发送 Outlook 电子邮件 - Send an outlook email without any permission using python library win32com.client Python win32com.client和outlook - Python win32com.client and outlook 想从 Python 发送一个 Outlook email 和 win32com.client 从另一个 email 地址默认 email 地址 - Want to send an Outlook email from Python with win32com.client from a other email address that default email address Python win32com.client和“with”语句 - Python win32com.client and “with” statement 如何通过Outlook使用其他邮件来源发送HTML电子邮件(win32com.client) - How to send HTML email through Outlook with a different mail-from (win32com.client) Python win32com.client - 只有当我打开 Outlook 时电子邮件才会发出 - Python win32com.client - Email only goes out when I have outlook open 尝试使用Python从Outlook 2007发送邮件(win32com.client) - Trying to send a mail from Outlook 2007 using Python (win32com.client) 如何使用 Python 中的 win32com.client 模块将邮件发送到多个客户端或组? - How to Send the mail to multiple clients or groups using win32com.client Module in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM