Python错误:5.7.0必须发出starttls命令firs

2024-05-19 12:03:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用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)

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


Tags: tofromcommessage错误mailsmtpsender

热门问题