Python错误:5.7.0必须首先发出一个starttls命令

时间:2013-06-07 10:11:18

标签: python email smtplib

我尝试使用我的python脚本发送电子邮件,但收到错误消息:

5.7.0 must issue a starttls command first

我正在使用smtplib,这是我的代码:

import smtplib

sender = 'from@fromdomain.com'
receivers = 'to@todomain.com'

message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test

This is a test e-mail message.
"""

try:
    smtpObj = smtplib.SMTP('smtp.gmail.com')
    smtpObj.sendmail(sender, receivers, message)         
    print "Successfully sent email"
except Exception,e:
    print str(e)

如果有人知道如何解决这个错误,我将不胜感激。

1 个答案:

答案 0 :(得分:4)

GMail不会让随机用户通过他们的SMTP服务器发送邮件。

如错误所示,您必须先调用SMTP.starttls并进行身份验证。