Is there any way to add multiple receivers in Python SMTPlib?

后端 未结 2 1744
迷失自我
迷失自我 2020-12-11 06:25

I was wondering. Is there any way to add multiple receivers in Python on its default SMTPlib?

Like (subject and content set already, smtp server gmail.):

<         


        
2条回答
  •  春和景丽
    2020-12-11 07:09

    Tested before posting!

    import smtplib
    from email.mime.text import MIMEText
    
    s = smtplib.SMTP('smtp.uk.xensource.com')
    s.set_debuglevel(1)
    msg = MIMEText("""body""")
    sender = 'me@example.com'
    recipients = ['john.doe@example.com', 'john.smith@example.co.uk']
    msg['Subject'] = "subject line"
    msg['From'] = sender
    msg['To'] = ", ".join(recipients)
    s.sendmail(msg.get('From'), recipients, msg.as_string())
    

提交回复
热议问题