Python 网易邮箱简单发送邮件

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

msg_from="130xxxxx490@163.com"    #发件人邮箱
passwd="xyy0820"  #客户端授权密码,不是邮箱登陆密码
msg_to="19xxxxxx59@qq.com"  #接收人邮箱

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()

代码如上,在运行过程中我们可能会遇到各种问题。

问题一、提示 import smtplib 报错  ,并且有Could not find a version that satisfies the requirement smtplib (from versions: )
No matching distribution found for smtplib
错误信息,是因为没有导入PyEamil第三方包。

 

问题二、提示ss.login(msg_from,passwd) 报错,并且有smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed' 错误信息,是因为passwd是客户端授权密码,不是邮箱登陆密码。

问题三、邮件的成功的发送需要开启邮件设置

其他链接帮助:https://www.cnblogs.com/secondtonone1/p/8213749.html   网易邮箱发送邮件升级代码

                        https://blog.csdn.net/dearmorning/article/details/81069075   网易邮箱发送邮件问题帮助

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值