Send email to multiple recipients using win32com module in Python

I use win32com to send emails after my code. However, I cannot figure out how to send it to more than one person. Now I can add myself only to cc, but not to the list of recipients.

Here is my code:

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']

An error has occurred:

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)

Can anyone help?

+4
source share
1 answer

Try semicolons:

newMail.To = 'Amy; john; sandy'

If you do an online search for "outlook interop createitem", you can find documents for MailItem.Towhere this is explained.

: Outlook script, Python script, Python win32com Outlook. , , VB/# Outlook COM ( OlItemType).

+5

Source: https://habr.com/ru/post/1533683/


All Articles