[英]SMTP server with python3
I'm trying to send an email to my webmail(yahoo) using python3 but I have some problems with the object.我正在尝试使用 python3 将 email 发送到我的网络邮件(雅虎),但 object 存在一些问题。 I've tried with different ports (25/465/587) without any success:
我尝试了不同的端口(25/465/587)但没有成功:
import smtplib
sender = 'manolo@yahoo.es'
receivers = ['raul@yahoo.es']
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_SSL('smtp.mail.yahoo.com', 465) ### 587)
smtpObj.set_debuglevel(1)
smtpObj.login(sender, pass)
smtpObj.sendmail(sender, receivers, message)
print("Successfully sent email")
except SMTPException:
print("Error: unable to send email")
And this is the error I get:这是我得到的错误:
send: 'ehlo [192.168.0.15]\r\n' reply: b'250-kubenode501.mail-prod1.omega.ir2.yahoo.com Hello [192.168.0.15] [81.61.24.111])\r\n' reply: b'250-PIPELINING\r\n' reply: b'250-ENHANCEDSTATUSCODES\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-SIZE 41697280\r\n' reply: b'250 AUTH PLAIN LOGIN XOAUTH2 OAUTHBEARER\r\n' reply: retcode (250);发送:'ehlo [192.168.0.15]\r\n' 回复:b'250-kubenode501.mail-prod1.omega.ir2.yahoo.com 你好 [192.168.0.15] [81.61.24.111])\r\n'回复:b'250-PIPELINING\r\n' 回复:b'250-ENHANCEDSTATUSCODES\r\n' 回复:b'250-8BITMIME\r\n' 回复:b'250-SIZE 41697280\r\n' 回复: b'250 AUTH PLAIN LOGIN XOAUTH2 OAUTHBEARER\r\n' 回复: retcode (250); Msg: b'kubenode501.mail-prod1.omega.ir2.yahoo.com Hello [192.168.0.15] [81.61.24.111])\nPIPELINING\nENHANCEDSTATUSCODES\n8BITMIME\nSIZE 41697280\nAUTH PLAIN LOGIN XOAUTH2 OAUTHBEARER' send: 'AUTH PLAIN AGF1c3RyYWxiaXRAeWFob28uZXMAQWFsaWNpYTAy\r\n' reply: b'535 5.7.0 (#AUTH005) Too many bad auth attempts.\r\n' reply: retcode (535);
MSG:B'Kubenode501.mail-prod1.omega.ir2.yahoo.z4d236d9a2d9a2d102c5fe6ad1c501c50da4bec50z Hello [192.168.0.0.15] [81.61.24.111]) AGF1c3RyYWxiaXRAeWFob28uZXMAQWFsaWNpYTAy\r\n' 回复:b'535 5.7.0 (#AUTH005) 错误的身份验证尝试太多。\r\n' 回复:retcode (535); Msg: b'5.7.0 (#AUTH005) Too many bad auth attempts.'
消息:b'5.7.0 (#AUTH005) 太多错误的身份验证尝试。' send: 'AUTH LOGIN YXVzdHJhbGJpdEB5YWhvby5lcw==\r\n' Error: unable to send email
发送:'AUTH LOGIN YXVzdHJhbGJpdEB5YWhvby5lcw==\r\n' 错误:无法发送 email
Any idea about how to fix this error?关于如何解决此错误的任何想法?
There are a few things to fix:有几件事情需要解决:
Use smtplib.SMTP_SSL('smtp.mail.yahoo.com', 465)
because port 465 expects connection using SSL.使用
smtplib.SMTP_SSL('smtp.mail.yahoo.com', 465)
因为端口465需要使用 SSL 进行连接。
Add smtpObj.set_debuglevel(1)
to have better help with debugging - this will tell you that you need to login first.添加
smtpObj.set_debuglevel(1)
以获得更好的调试帮助 - 这将告诉您需要先登录。
Use smtpObj.login("login", "password")
before trying to send an email.在尝试发送 email 之前使用
smtpObj.login("login", "password")
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.