I try to send mails from python to multiple email-addresses, imported from a .txt file, I've tried differend syntaxes, but nothing would work...
The code:
s.sendmail('[email protected]', ['[email protected]', '[email protected]', '[email protected]'], msg.as_string())
So I tried this to import the recipient-addresses from a .txt file:
urlFile = open("mailList.txt", "r+")
mailList = urlFile.read()
s.sendmail('[email protected]', mailList, msg.as_string())
The mainList.txt contains:
['[email protected]', '[email protected]', '[email protected]']
But it doesn't work...
I've also tried to do:
... [mailList] ... in the code, and '...','...','...' in the .txt file, but also no effect
and
... [mailList] ... in the code, and ...','...','... in the .txt file, but also no effect...
Does anyone knows what to do?
Thanks a lot!
sendmail() function. In short, to send to multiple recipients you should set the header to be a string of comma delimited email addresses. The sendmail() parameter to_addrs however should be a list of email addresses.
For smtp you need to have port number, logon email address and in To:"[email protected];[email protected]" … try this out.
You can send a mass email to more than one recipient using the BCC feature. Click the compose box, after composing your message, click on BCC and add all your recipients. This will send the emails to the recipients keeping email addresses hidden from each other.
This question has sort of been answered, but not fully. The issue for me is that "To:" header wants the emails as a string, and the sendmail function wants it in a list structure.
# list of emails
emails = ["[email protected]", "[email protected]", "[email protected]"]
# Use a string for the To: header
msg['To'] = ', '.join( emails )
# Use a list for sendmail function
s.sendmail(from_email, emails, msg.as_string() )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With