使用 win32com 将签名添加到带有 python 的 Outlook 电子邮件 [英] Add signature to outlook email with python using win32com

查看:68
本文介绍了使用 win32com 将签名添加到带有 python 的 Outlook 电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何使用 win32com 在电子邮件中添加电子邮件签名?

将 win32com.client 导入为 win32Outlook = win32.Dispatch('outlook.application')邮件 = Outlook.CreateItem(0)mail.To = 'TO'mail.Subject = 'SUBJECT'mail.HTMLbody = 'BODY'邮件发送

解决方案

Outlook 签名不会通过 Outlook 对象模型公开.您能做的最好的事情是从文件系统中读取签名并将其内容适当地添加到 HTML 正文中.请记住,两个 HTML 字符串必须合并,而不仅仅是连接.您还需要合并来自两个 HTML 文档的样式并处理签名使用的嵌入图像.

请注意,当显示未修改的邮件或触摸其检查器时,Outlook 会添加签名

将 win32com.client 导入为 win32Outlook = win32.Dispatch('outlook.application')邮件 = Outlook.CreateItem(0)mail.To = 'TO'mail.Subject = 'SUBJECT'邮件.GetInspector

mail.HTMLBody 现在包含您需要与您自己的 HTML 合并(不仅仅是连接!)的消息签名

更新:从最新版本(2016 年夏季)开始,Outlook、GetInspector 技巧不再有效.现在只有 MailItem.Display 将签名添加到未修改的邮件中.
如果您想以编程方式插入签名,Redemption 公开 RDOSignature 对象,它实现了 ApplyTo 方法(它处理签名图像文件并适当地合并 HTML 样式).>

Does anyone know how to add an email signature to an email using win32com?

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'TO'
mail.Subject = 'SUBJECT'
mail.HTMLbody = 'BODY'
mail.send

解决方案

Outlook signatures are not exposed through the Outlook Object Model. The best you can do is read the signature from the file system and add its contents to the HTML body appropriately. Keep in mind that two HTML strings must be merged, not just concatenated. You would also need to merge the styles from two HTML documents and take care of the embedded images used by the signature.

Note that Outlook adds a signature when an unmodified message is displayed or its inspector is touched

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'TO'
mail.Subject = 'SUBJECT'
mail.GetInspector 

mail.HTMLBody now contains the message signature that you will need to merger (not just concatenate!) with your own HTML

UPDATE: as of the latest (Summer 2016) builds of Outlook, GetInspector trick no longer works. Now Only MailItem.Display adds the signature to an unmodified message.
If you want to programmatically insert a signature, Redemption exposes RDOSignature object which implements ApplyTo method (it handles the signature image files and merges HTML styles appropriately).

这篇关于使用 win32com 将签名添加到带有 python 的 Outlook 电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆