python 默认使用密件抄送而不是收件人发送电子邮件
python emailing using BCC by default instead of To
我正在尝试创建一个简单的 python 程序来发送电子邮件。这是相关的代码行。我希望它使用“收件人”字段发送电子邮件。当我 运行 程序并检查测试电子邮件帐户时,程序似乎是通过 BCC 发送的。
这里是相关的代码行。
smtp = smtplib.SMTP(server)
smtp.sendmail(send_from,["testaddress@testdomain.com"],"hello")
是否有我遗漏的设置?
来自https://docs.python.org/2/library/smtplib.html#smtplib.SMTP.sendmail:
Note The from_addr and to_addrs parameters are used to construct the message envelope used by the transport agents. The SMTP does not modify the message headers in any way.
所以这意味着您构建了收件人将在邮件 body 中看到的 "To:" headers,但在 to_addrs
中选择邮件将转到的实际收件人] 参数到 sendmail
。例如:
message='To: {}\r\nSubject: {}\r\n\r\n{}'.format('visible@example.com', subject, body)
smtp = smtplib.SMTP(server)
smtp.sendmail(send_from, ['visible@example.com', 'invisible@example.com'], message)
smtp.quit()
和 invisible@example.com
将被密件抄送。
我正在尝试创建一个简单的 python 程序来发送电子邮件。这是相关的代码行。我希望它使用“收件人”字段发送电子邮件。当我 运行 程序并检查测试电子邮件帐户时,程序似乎是通过 BCC 发送的。
这里是相关的代码行。
smtp = smtplib.SMTP(server)
smtp.sendmail(send_from,["testaddress@testdomain.com"],"hello")
是否有我遗漏的设置?
来自https://docs.python.org/2/library/smtplib.html#smtplib.SMTP.sendmail:
Note The from_addr and to_addrs parameters are used to construct the message envelope used by the transport agents. The SMTP does not modify the message headers in any way.
所以这意味着您构建了收件人将在邮件 body 中看到的 "To:" headers,但在 to_addrs
中选择邮件将转到的实际收件人] 参数到 sendmail
。例如:
message='To: {}\r\nSubject: {}\r\n\r\n{}'.format('visible@example.com', subject, body)
smtp = smtplib.SMTP(server)
smtp.sendmail(send_from, ['visible@example.com', 'invisible@example.com'], message)
smtp.quit()
和 invisible@example.com
将被密件抄送。