[英]Python how to insert images using win32com.client and outlook?
I'm trying to send html emails using win32com.client. 我正在尝试使用win32com.client发送html电子邮件。 Here's a sample code:
这是一个示例代码:
import win32com.client as win32
mail = win32.Dispatch('outlook.application').CreateItem(0)
mail.To = 'sample@sample.com'
mail.Subject = 'test'
mail.HTMLBody = html_pages
mail.Send()
My solution now is to upload the images to a server and insert the urls into html_pages. 我现在的解决方案是将图像上传到服务器,并将网址插入html_pages。 The drawback is that the images are not displayed when the server is down.
缺点是在服务器关闭时不显示图像。 Is there a way to send the images with the emails using win32com?
有没有一种方法可以使用win32com通过电子邮件发送图像?
One way to do that would be sending images as an attachment: 一种方法是将图像作为附件发送:
import win32com.client as win32
mail = win32.Dispatch('outlook.application').CreateItem(0)
mail.To = 'sample@sample.com'
mail.Subject = 'test'
mail.HTMLBody = html_pages
attachment = '*path to your image*'
mail.Attachments.Add(attachment)
mail.Send()
Or you can put image in the html body: 或者您可以将图像放在html正文中:
import win32com.client as win32
mail = win32.Dispatch('outlook.application').CreateItem(0)
mail.To = 'sample@sample.com'
mail.Subject = 'test'
mail.HTMLBody = html_pages + <br><img src="path">
mail.Send()
Or if you want the image actually attached to the body and not being linked to a path, have a look here: 或者,如果您希望图像实际附着在身体上而不是链接到路径,请在此处查看:
I am not able to add an image in email body using python , I am able to add a picture as a attachment but i want a code to add image in mailbody 我无法使用python在电子邮件正文中添加图片,我可以添加图片作为附件,但我想要代码在邮件正文中添加图片
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.