嘿,我想给一群人发一封电子邮件,但由于某种原因,即使打印输出是多封电子邮件,程序也只能将电子邮件发送给文本的第一人称,我能做什么?
# 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必须是一个字符串对象,其地址由"&";。
示例:
send_to='xyz1@gmail.com,hhdasn@yahoo.com'
执行电子邮件发送的行是server.sendmail(mail_from, mail_to, mail_message)
。你只打过一次电话。您可以将print(mail_to)
语句放在它旁边进行检查。
如果您想多次发送电子邮件,则需要循环调用sendmail
。