Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Multiple Emails using Outlook

Tags:

python

I want to write code that sends out emails to multiple clients (individually).

address = ['[email protected]','[email protected]','[email protected]','[email protected]']
ticketnumbers = ['1','2','3','4']
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
z = 0 
while z < len(address):
    mail = outlook.CreateItem(z)
    z = z + 1

i = 0  
while i < len(address):
    mail.To = address[i]
    mail.Subject = 'SUBJECT'
    mail.Body = '''
Hello,

This is a test message!

Thanks,

JC
''' + ticketnumbers[i]
    
    mail.Send()
    i = i + 1

However I keep getting the following error:

[1]: https://i.sstatic.net/FqVrw.png

How would I iterate through the address and the ticketnumbers lists so it's applied to each message individually?

Thanks!

like image 800
Jacob3454 Avatar asked Jul 22 '26 00:07

Jacob3454


1 Answers

You can directly add ; to mail. To object like below mail. To = "[email protected];[email protected]" You can put as many mails you want with ; in python its works for mail.CC also.

like image 69
Angela Avatar answered Jul 23 '26 14:07

Angela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!