SMTPNotSupporteror: 服务器不支持 STARTTLS 扩展

我正在尝试使用smtplib发送邮件,我得到了如下错误,我搜索了有关此错误的其他主题,但我找不到解决方案。有人可以帮助我吗?


法典:


import smtplib

from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText

from email.mime.base import MIMEBase

from email import encoders

toaddr = "mailto@mail.com"

head = "TRY"  

body = "XxX"

fromaddr = "mailsender@mail.com"

msg = MIMEMultipart()

msg['From'] = fromaddr

msg['To'] = toaddr

msg['Subject'] = head

password = "password"

msg.attach(MIMEText(body, 'plain'))

server = smtplib.SMTP('SMTP', 25)

server.connect('SMTP', 25)

server.starttls()

server.ehlo()

server.login(fromaddr, password)

text = msg.as_string()

server.sendmail(fromaddr, toaddr, text)

server.quit()

错误:


SMTPNotSupportedError                     Traceback (most recent call last)

<ipython-input-4-357dd2da8ab1> in <module>

 17 server = smtplib.SMTP('mailenable', 25)

 18 server.connect('mailenable', 25)

 ---> 19 server.starttls()

 20 server.ehlo()

 21 server.login(fromaddr, password)


 /opt/anaconda/envs/env_python/lib/python3.6/smtplib.py in starttls(self, keyfile, certfile, context)

 750         if not self.has_extn("starttls"):

 751             raise SMTPNotSupportedError(

 --> 752                 "STARTTLS extension not supported by server.")

 753         (resp, reply) = self.docmd("STARTTLS")

 754         if resp == 220:


 SMTPNotSupportedError: STARTTLS extension not supported by server.


holdtom
浏览 252回答 1
1回答

扬帆大鱼

弄清楚了这个问题。只需删除此行。server.starttls()server.ehlo()server.login(fromaddr, password)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python