Python通过Outlook在答复中添加CC收件人

时间:2019-09-30 11:09:06

标签: python

我正在通过主题搜索Outlook中的一个项目,想对CC中所有添加3个ID的内容进行重播。

可以轻松地在“收件人”中添加更多收件人,但不能在抄送中添加更多收件人,请帮助

 rplyall.Recipients.Add(message.sender.address)
 rplyall.Recipients.Add('one.more@abc.com')  

同样的方式想要做

rplyall.Recipients.CC.Add(message.all.CC.address)
rplyall.Recipients.CC.Add('one.moreinCC@abc.com')

outlook=win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox= outlook.Folders.Item(1).Folders['Inbox']
messages = inbox.Items
message = messages.GetLast()
count=0
for i, message in enumerate(messages):
    # Search Mail
    if message.subject=='Search Filter by Subject':
        rplyall=message.ReplyAll()
        rplyall.Recipients.Add(message.sender.address) # Sender of the mail
        rplyall.Recipients.Add('one.more@abc.com')     # Addational Email ID

        lis_for_cc=['first_in_cc@abc.com','second_in_cc@abc.com']

        # Add more ids in CC from above list
        for mail_id in lis_for_cc:
            rplyall.Recipients.CC.Add(mail_id)

        rplyall.Body='Testing reply all'
        rplyall.Subject = 'Subject Reply to all 2'

        rplyall.Send()

2 个答案:

答案 0 :(得分:1)

您可以通过直接编辑CC属性或更新Type中返回的收件人对象返回的Recipients.Add属性来添加CC收件人

更新收件人类型

newCC = rplyall.Recipients.Add('one.more@abc.com')     
newCC.Type = 2 #2 = olCC

更改抄送属性

rplyall.CC = 'one.more@abc.com;two.more@abc.com'

https://docs.microsoft.com/en-us/office/vba/api/outlook.recipients

答案 1 :(得分:0)

更正我自己的问题帖子的答案,从上面的帖子中获得Mike的答案。

 import win32com.client

outlook=win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox= outlook.Folders.Item(1).Folders['Inbox']
messages = inbox.Items
message = messages.GetFirst()
count=0

for i, message in enumerate(messages):
    print(message.subject)
    rplyall = message.ReplyAll()
    rplyall.Recipients.Add('hitesh@abc.com') # Sender of the mail
    rplyall.CC = 'deepak@abc.com'
    rplyall.Body = 'Testing reply all'
    rplyall.Subject = 'Subject Reply to all TEST'
    rplyall.Send()