[英]Hey I want to send email to more than one person with python
Hey i want to send an email to a bunch of people but for some reason even if the output of print is more than one email the program sending the email only to first person of the text what can i do?
# Import Python Packages
import smtplib
# Set Global Variables
gmail_user = 'your@gmail.com'
gmail_password = 'password'
# Create Email
mail_from = gmail_user
for i in range(2):
with open('C:\\email.txt', 'r', encoding="utf8") as f
mail_to = f.read().rstrip()
mail_subject = 'subject'
mail_message_body = 'body'
mail_message = '''\
From: %s
To: %s
Subject: %s
%s
''' % (mail_from, mail_to, mail_subject, mail_message_body)
# Sent Email
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login(gmail_user, gmail_password)
server.sendmail(mail_from, mail_to, mail_message)
print(mail_to)
server.close()
Send_to 必须是一个字符串 object,地址用“,”分隔。
例子:
send_to='xyz1@gmail.com,hhdasn@yahoo.com'
执行 email 发送的行是server.sendmail(mail_from, mail_to, mail_message)
。 你叫它一次。 您可以通过在它旁边放置print(mail_to)
语句来检查它。
如果要多次发送 email,则需要循环调用sendmail
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.