[英]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?
除了 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.