将Outlook邮件发送到Python中的多个通讯组列表 [英] Sending Outlook mail to multiple distribution lists in Python

查看:343
本文介绍了将Outlook邮件发送到Python中的多个通讯组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python和win32com.client将Outlook邮件发送到多个通讯组列表,如下所示:

I'm using Python and win32com.client to send Outlook mails to multiple distribution lists like so:

olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "This is subject"
newMail.To = "abc@company.com"
newMail.CC = "samplegrp1; samplegrp2"   # offending statement
//some html processing in mail content
newMail.Send()

上面的代码可以通过以下方式发送到单个组:

The above code works as I'm able to send to a single group using:

newMail.CC = "samplegrp1"

但是当我尝试发送到多个组(上面有问题的语句)时,出现以下错误:

but when I try to send to multiple groups (the offending statement above), I receive the following error:

>     return self._oleobj_.InvokeTypes(61557, LCID, 1, (24, 0), (),)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Out
look', 'Outlook does not recognize one or more names. ', None, 0, -2147467259),
None)

我尝试使用逗号代替分号,使用+运算符等,但无济于事.

I tried using comma instead of semicolon, using + operator, etc. but to no avail.

如果有人可以帮助,谢谢.

If anyone can help, thanks.

推荐答案

尝试一下:

from win32com.client.gencache import EnsureDispatch
from win32com.client import constants

outlook = EnsureDispatch("Outlook.Application")
newMail = outlook.CreateItem(constants.olMailItem)
newMail.Subject = "This is subject"

samplegrp1 = newMail.Recipients.Add("samplegrp1")
samplegrp2 = newMail.Recipients.Add("samplegrp2")
samplegrp1.Type = constants.olCC
samplegrp3.Type = constants.olCC
newMail.Recipients.ResolveAll()

此文档记录在如何:指定邮件项目的不同收件人类型.

这篇关于将Outlook邮件发送到Python中的多个通讯组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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