服务器不支持 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()
相关文章