简体   繁体   English

Python如何使用win32com.client和Outlook插入图像?

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

相关问题 Python win32com.client和outlook - Python win32com.client and outlook 使用 python (win32com.client) 将图像插入幻灯片 - Insert images to powerpoint slide using python (win32com.client) 如何在 Python 中使用 win32com.client 保存 Outlook 中的附件? - How to save attachment from outlook using win32com.client in Python? 如何使用Python和win32com.client过滤主题上的Outlook邮件? - How to filter outlook mails on a subject using Python and win32com.client? Python Outlook 收件箱保存附件 win32com.client - Python Outlook inbox saving attachments win32com.client 尝试使用Python从Outlook 2007发送邮件(win32com.client) - Trying to send a mail from Outlook 2007 using Python (win32com.client) 使用 python 库 win32com.client 在没有任何许可的情况下发送 Outlook 电子邮件 - Send an outlook email without any permission using python library win32com.client 使用任务计划程序 (Python) 通过 win32com.client 运行 Outlook - Running Outlook through win32com.client using Task Scheduler (Python) 使用python win32com.client dispatch或dispatchex阅读Outlook消息时绕过安全框 - Bypassing security box when reading outlook messages using python win32com.client dispatch or dispatchex 如何使用 python 和 win32com.client 从 Outlook 的电子邮件项目中访问 c​​c 电子邮件地址 - How to access cc email address from email items from outlook using python and win32com.client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM