0

I am searching an item in outlook through subject , want to do replay to all adding 3 ids in CC.

Easily able to add more recipients in To but not in CC please help

import win32com.client

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('hitesh.kumar@bhartiaxa.com') # Sender of the mail
    rplyall.Recipients.CC('one.more@abc.com')     # Trying to do this
    rplyall.Copy('one.more@abc.com')
    rplyall.Body='Testing reply all'
    rplyall.Subject = 'Subject Reply to all 2'

    rplyall.Send()
    
Hietsh Kumar
  • 1,197
  • 9
  • 17

2 Answers2

2

You can add CC recipients by editing the CC property directly or updating the Type property of the returned from the returned Recipient object from Recipients.Add

Updating the recipient type

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

Changing the CC property

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

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

Mike
  • 624
  • 4
  • 14
  • 1
    CC property is very much editable, you can either call Recipients.Add or set the CC property to a semicoln separated list: `rplyall.CC = 'user1@test.demo;user2@test2.demo;user3@test3.demo'` – Dmitry Streblechenko Aug 31 '20 at 23:34
  • @DmitryStreblechenko Absolutely correct - updated to reflect. – Mike Sep 01 '20 at 01:29
0

Correcting the answer to my own question post getting the answer from Mike in above post.

 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()
Hietsh Kumar
  • 1,197
  • 9
  • 17