简体   繁体   中英

How do I send multiple users an email through smtplib in python?

I have created the app and it works perfectly and sends an alert. However, at this time it is only able to send one user an email. How can I add more users as recipients apart from jbxl.t@cfo.com?

import pandas as pd
import smtplib
from email.message import EmailMessage

df = pd.read_fwf(r'factadwords.Rout', header=None)
end_str = '#--- END ---------------------------------------------------------------------------------------------------'
cols_to_check = ["0"]


def email_alert(subject,body,to):
    msg = EmailMessage()
    msg.set_content(body)
    msg['subject'] = subject
    msg['to'] = to
        
    user = "yyyw@gmail.com"
    msg['from'] = user
    password = "xxxxx"
        
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login(user,password)
    server.send_message(msg)
        
    server.quit()

if __name__ == '__main__':

    for col in cols_to_check:
        if not df[0].str.contains(end_str).any():
            body = "There is no one in factadwords " + col + "."
            print(body)
            email_alert("Rout",body,"jbxl.t@cfo.com")

您需要做的就是将更多用户添加到您的收件人字符串中

email_alert("Rout",body,"jbxl.t@cfo.com, x@gmail.com, y@gmail.com")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM