使用Python中的win32com模块将电子邮件发送给多个收件人 [英] Send email to multiple recipients using win32com module in Python

查看:469
本文介绍了使用Python中的win32com模块将电子邮件发送给多个收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码完成后,我正在使用win32com发送电子邮件。但是,我不知道如何将其发送给多个人。现在,我只能将自己添加到抄送中,而不能添加到收件人列表中。

I am using win32com to send emails after my code is done. However, I cannot figure out how to send it to more than 1 person. Now I can only add myself in cc, but not in the recipient list.

这是我的代码:

import win32com.client
import datetime as date

olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = 'Hi'
newMail.Body = 'Hi'
newMail.To = 'Amy'
newMail.CC = 'Bob'    
newMail.Send()

但是,如果我尝试这样做:

However if I try this:

newMail.To = ['Amy','Bob']

发生错误:

pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, u'Microsoft Office Outlook', u'Type Mismatch: Cannot coerce parameter value. Outlook cannot translate your string.', None, 0, -2147352571), 1)

有人可以帮忙吗?

推荐答案

尝试用分号分隔:

newMail.To = 'Amy; john; sandy'

如果您在网络上搜索 outlook interop createitem,则可以找到 MailItem.To 进行解释。

If you do a web search for "outlook interop createitem" you can find the docs for MailItem.To where this is explained.

更新:这不是Outlook脚本,而是Python脚本,使用Python的win32com模块来控制Outlook。我要指的文档是Outlook COM接口的VB / C#文档(例如OlItemType的可能值)。

Update: this is not an Outlook script, it is a Python script that uses Python's win32com module to control Outlook. The docs I'm referring to are the VB/C# docs for Outlook's COM interface (for example the possible values of OlItemType).

这篇关于使用Python中的win32com模块将电子邮件发送给多个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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