python实现发送邮件的功能主要是依靠yagmail这个库来实现的;
具体需要做的步骤如下;
一、开启发送邮箱的授权密码功能
简单了解一下邮件协议:
http://help.163.com/09/1223/14/5R7P6CJ600753VB8.html
目的:用生成的授权密码作为发送密码,但该密码并不是真的邮箱密码;
具体操作步骤可参考:https://jingyan.baidu.com/article/456c463b42f55e4b59314468.html
二、python中安装yagmail库
三、开始写代码
import yagmail
#发送发邮箱的相关信息
data={
"user":"邮箱名称@qq.com",
"password":"第一步中生成的授权密码",
"host":"smtp.qq.com"
}
yag=yagmail.SMTP(user=data['user'],password=data['password'],host=data['host'])
contents="Hello yangyue! Testing send email!"
yag.send(to="接收邮箱名称@qq.com",subject="send email test.",contents=contents)
yag.close()
成功!
四、基本就这样吧!
大致过程是这个步骤,等之后深入了解了,再进行细节补充吧。