[英]Difficulty sending e-mail using python
I am trying to get Python to send e-mails. 我正在尝试让Python发送电子邮件。 First, I started python smptd as follows:
首先,我如下启动python smptd:
python -m smtpd -n -c DebuggingServer localhost:1025
Then, adapting the example from https://www.tutorialspoint.com/python/python_sending_email.htm , I have the following script: 然后,从https://www.tutorialspoint.com/python/python_sending_email.htm改编示例,我有以下脚本:
#!/usr/bin/python
import smtplib
sender = 'from@fromdomain.com'
receivers = ['brt381@gmail.com']
message = """From: From Person <from@fromdomain.com>
To: To Person <brt381@gmail.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost:1025')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
When I run this script, I get the message "Successfully sent email". 运行此脚本时,我收到消息“成功发送电子邮件”。 In my other terminal window (the one containing the python smptd), it shows this after running the script:
在我的另一个终端窗口(包含python smptd的窗口)中,运行脚本后显示了此信息:
---------- MESSAGE FOLLOWS ----------
From: From Person <from@fromdomain.com>
To: To Person <brt381@gmail.com>
Subject: SMTP e-mail test
X-Peer: ::1
This is a test e-mail message.
------------ END MESSAGE ------------
But... no e-mail gets sent. 但是...没有电子邮件被发送。 Any idea what might be wrong?
知道有什么问题吗? This works just fine - the e-mail gets sent:
这很好用-电子邮件已发送:
/usr/sbin/sendmail brt381@gmail.com <<<"hello"
You are actually sending (in the first example) your email through a local development smtp server, because you mention the DebuggingServer
class which, as the documention says : 您实际上是通过本地开发smtp服务器发送(在第一个示例中)您的电子邮件,因为您提到了
DebuggingServer
类,正如文档所述 :
Create a new debugging server.
创建一个新的调试服务器。 Arguments are as per SMTPServer.
参数根据SMTPServer。 Messages will be discarded, and printed on stdout.
消息将被丢弃,并在标准输出上打印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.