Python NetEase mailbox simply sends emails

import smtplib   #导入PyEmail
from email.mime.text import MIMEText

msg_from="[email protected]"    #发件人邮箱
passwd="xyy0820"  #客户端授权密码,不是邮箱登陆密码
msg_to="[email protected]"  #接收人邮箱

subject="邮件主题"
content="邮件内容"
msg=MIMEText(content)
msg["Subject"]=subject
msg["From"]=msg_from
msg["To"]=msg_to

try:
    #s = smtplib.SMTP_SSL("smtp.163.com",465)
    s = smtplib.SMTP("smtp.163.com",25)
    s.login(msg_from, passwd)
    s.sendmail(msg_from, msg_to, msg.as_string())
    print ("发送成功")
except smtplib.SMTPException as e:
    print ("发送失败")
finally:
    s.quit()

The code is as above, we may encounter various problems during operation.

Question 1. It prompts that import smtplib reports an error, and there is the error message Could not find a version that satisfies the requirement smtplib (from versions: )
No matching distribution found for smtplib
. This is because the PyEamil third-party package is not imported.

 

Question 2: It prompts that ss.login(msg_from,passwd) reports an error, and there is an error message smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed' , because passwd is the client authorization password, not the email login password.

Question 3: Successful sending of emails requires turning on email settings

Other links for help: https://www.cnblogs.com/secondtonone1/p/8213749.html    NetEase mailbox sends an email upgrade code

                        https://blog.csdn.net/dearmorning/article/details/81069075Help    with problems sending emails via NetEase mailbox

Guess you like

Origin blog.csdn.net/tjfsuxyy/article/details/87857452