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

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

问题描述

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

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签名不通过Outlook对象模型公开.最好的办法是从文件系统中读取签名,并将其内容适当地添加到HTML正文中.请记住,必须合并两个HTML字符串,而不仅仅是合并它们.您还需要合并两个HTML文档中的样式,并照顾签名使用的嵌入图像.

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.

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

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现在包含您需要与您自己的HTML合并(而不仅仅是连接!)的消息签名

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

更新:从Outlook, GetInspector技巧的最新版本(2016年夏季)起,该版本不再有效.现在,只有MailItem.Display将签名添加到未修改的消息中.
如果要以编程方式插入签名,则兑换公开

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天全站免登陆