I want to send automated mails from my outlook to some email addresses using python win32com.
This is the code I am using -
def Emailer(text, subject, recipient):
import win32com.client as win32
import os
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
cc_address = '[email protected]'
# mail.CC = f"<{cc_address.strip()}>"
mail.Subject = subject
mail.HtmlBody = text
print("To:", mail.To)
###
# attachment1 = os.getcwd() +"\\file.ini"
#
# mail.Attachments.Add(attachment1)
###
mail.Send()
MailSubject= "Auto test mail"
MailInput= " This is test mail"
MailAdress="[email protected];[email protected]"
Emailer(MailInput, MailSubject, MailAdress )
I am able to send the mail successfully when mail.CC is not defined / commented.
But when I add recipients in mail.CC. I am getting the following error -
2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The object does not support this method.', None, 0, -2147352567), None)
Is there any other way of adding CC recipients?