本文介绍了为什么我无法使用此脚本将电子邮件发送给多个收件人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能用这个脚本发送电子邮件给多个收件人?

Why can't I send emails to multiple recipients with this script?

我没有错误或反弹,第一个收件人 >收到电子邮件。

I get no errors nor bouncebacks, and the first recipient does receive the email. None of the others do.

脚本:

#!/usr/bin/python
import smtplib

SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587

recipient = '[email protected]; [email protected];'
sender = '[email protected]'
subject = 'the subject'
body = 'the body'
password = "password"
username = "[email protected]"

body = "" + body + ""

headers = ["From: " + sender,
           "Subject: " + subject,
           "To: " + recipient,
           "MIME-Version: 1.0",
           "Content-Type: text/html"]
headers = "\r\n".join(headers)

session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)

session.ehlo()
session.starttls()
session.ehlo
session.login(username, password)

session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
session.quit()


推荐答案

分号不是收件人标题中地址的正确分隔符。您必须使用逗号。

Semicolons are not the correct separator for addresses in recipient headers. You must use commas.

编辑:我现在看到您正在错误地使用该库。您提供的字符串总是会被解释为单个地址。您必须提供发送给多个收件人的地址列表。

I see now that you are using the library incorrectly. You're supplying a string which will always be interpreted as a single address. You must supply a list of addresses to send to multiple recipients.

这篇关于为什么我无法使用此脚本将电子邮件发送给多个收件人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:54