上代码:
import yagmail sendmail = 'xxx@126.com' sendpswd = 'xxx' receivemail = 'xxx@qq.com' # 连接邮箱服务器 yag = yagmail.SMTP(user=sendmail, password=sendpswd, host='smtp.126.com') # ①普通邮件正文 contents = ['第一段', '自动化', '报告邮件'] # ②发送html邮件正文 # 读取邮件模板 file_object = open('mailcontent.html') try: contentsbody = file_object.read() finally: file_object.close() contents = contentsbody # 附件地址 fujian = ["/Users/zhan/zhan/Autotest/report/2018-09-11_09_52_24_report.html"] # 发送邮件附件 yag.send(receivemail, '《自动化报告》', contents,fujian)
参考:《利用yagmail实现邮件自动发送》