Python Not Sending Email To Multiple Addresses

后端 未结 3 1006
忘掉有多难
忘掉有多难 2020-12-31 23:14

I can\'t see where i\'m going wrong with this, I hope someone can spot the problem. I\'d like to send an email to multiple addresses; however, it only sends it to the first

3条回答
  •  鱼传尺愫
    2020-12-31 23:30

    Try to use this code, without your join:

    import smtplib
    from smtplib import SMTP
    
    recipients = ['example1@gmail.com', 'example2@example.com']
    
    def send_email (message, status):
        fromaddr = 'from@gmail.com'
        server = SMTP('smtp.gmail.com:587')
        server.ehlo()
        server.starttls()
        server.ehlo()
        server.login('example_username', 'example_pw')
        server.sendmail(fromaddr, recipients, 'Subject: %s\r\n%s' % (status, message))
        server.quit()
    
     send_email("message","subject")
    

    Hope it helps!

提交回复
热议问题