python发送邮件yagmail的简单使用

yagmail发送邮件只需要3行代码就可以搞定,首先安装yagmail:pip install yagmail

demo如下:

#  todo 导入邮件服务器
import yagmail

sender = '[email protected]'     # 发送人邮箱账号
password = 'ersbmrvcnscebab'    # 发送人邮箱授权码,而不是邮箱密码
res = '[email protected]'      # 收件人邮箱账号

yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com', smtp_ssl=True)
content = r'D:\file\Report\test_2019_09_10_23_03_17_834.html'
yag.send(to=res, subject='测试报告', contents=content)

运行报错:SMTPAuthenticationError解决方法:https://blog.csdn.net/qq_39241986/article/details/81349270

获取邮箱验证码:https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256

猜你喜欢

转载自www.cnblogs.com/xiamaojjie/p/11741491.html
今日推荐