yagmail 实现发邮件

 

安装

pip install yagmail

实现

#导入发送邮件API
import yagmail

#链接邮箱服务器
yag = yagmail.SMTP( user="xxx@163.com", password="邮箱smtp授权码", host='smtp.163.com')

#添加邮件标题
subject = "这是一个测试邮件"

# 邮箱正文
contents = ['测试邮件内容']

#添加发送人
email_name = ['1xxxx@163.com','xxxxxx@qq.com']

# 发送邮件
yag.send(email_name, subject, contents)

补充:

1,代码是用python写的。

2,邮箱必须开通smtp服务。

3,如果报错SMTPAuthenticationError: (535, 'Error: authentication failed'),一定是邮箱授权码要么没写对,要么smtp服务没开启。

posted @ 2018-07-04 11:04  奢华使命  阅读(484)  评论(0)    收藏  举报