我使用以下代码我可以向一个帐户发送电子邮件,但如何发送到多帐户?
import smtplib
from email.mime.text import MIMEText
_user = "67676767@qq.com" #
_pwd = "orjxywulscbxsdwbaii" #
_to = linux213@126.com" #
msg = MIMEText("content") #
msg["Subject"] = "邮件主题测试" #
msg["From"] = _user
msg["To"] = _to
try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(_user, _pwd)
s.sendmail(_user, _to, msg.as_string())
s.quit()
print ("Success!")
except smtplib.SMTPException as e:
print ("Falied,%s" % e)
答案 0 :(得分:-1)
试试这个:
import smtplib
from email.mime.text import MIMEText
s = smtplib.SMTP('smtp.qq.com')
s.set_debuglevel(1)
msg = MIMEText("""body""")
sender = 'me@example.com'
recipients = ['k.ankur@abc.com', 'a.smith@abc.co.in']
msg['Subject'] = "subject line"
msg['From'] = sender
msg['To'] = ", ".join(recipients)
s.sendmail(sender, recipients, msg.as_string())