服务器不支持 SMTP AUTH 扩展

SMTP AUTH extension not supported by server(服务器不支持 SMTP AUTH 扩展)

本文介绍了服务器不支持 SMTP AUTH 扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 python 我想从我的应用程序发送电子邮件,但它显示错误

Using python I want to send email from my app but it shows the error

SMTP AUTH extension not supported by server

程序代码,

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = "test1@example.com"
toaddr = "test2@example.com"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Test Mail"
body = "Test mail from python"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.example.com', 25)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

Telnet 输出:

ehlo test1.example.com
250-hidden
250-HELP
250-SIZE 104857600
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-STARTTLS
250 OK

我需要验证并从应用发送邮件.

I need to authenticate and send mail from app.

推荐答案

登录和发送邮件前需要连接.

a connection is required before login and sendemail.

server = smtplib.SMTP('smtp.example.com', 25)
server.connect("smtp.example.com",465)
server.ehlo()
server.starttls()
server.ehlo()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

这篇关于服务器不支持 SMTP AUTH 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:服务器不支持 SMTP AUTH 扩展

基础教程推荐