- 使用模块yagmail(使用收藏的yagmail,现在的第三方模块不能解决中文乱码问题)
import yagmail user='xxx@126.com' password='xxxxxx' #使用邮件授权码 m=yagmail.SMTP(host='smtp.126.com',user=user,password=password) #smtp.qq.com #smtp_ssl=True 如果是qq邮箱的话,加这个参数 m.send(to=['xxx@126.com','xxx@qq.com'], cc='xxx@xxx.com', subject='测试邮件', contents='各位好, 附件是iFusionV4.1接口测试报告,请查阅。 谢谢。', attachments='my.log')
- 如果有多个收件人或抄送人的话,使用列表存放邮箱
- 如果使用qq邮箱当发件人的话,需要在.SMTP的参数中加入smtp_ssl=True,host='smtp.qq.com'
- attachments是附件,最好写最对路径