Send Email to multiple recipients from .txt file with Python smtplib

前端 未结 5 731
不思量自难忘°
不思量自难忘° 2020-12-06 08:23

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:



        
5条回答
  •  爱一瞬间的悲伤
    2020-12-06 08:45

    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 = ["banjer@example.com", "slingblade@example.com", "dude@example.com"]
    
    # 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() )
    

提交回复
热议问题