最最简单方法-》建议用着这个
方法一:
参考地址:https://www.cnblogs.com/fnng/p/7967213.html
import yagmail
yag = yagmail.SMTP( user="liudxxxx0@163.com", password="ldhxxxxxx0", host='smtp.163.com')
# 邮箱正文
contents = ['你好,测试报告在附件中,',
'请查看并知悉.',
'谢谢!']#想换行用逗号隔开
# 发送邮件
yag.send('liudhxxxxxxx@163.com', '测试报告通知', contents,["C:\\Users\\ldh\\Desktop\python 第三方库安装.xmind"])
运行结果
邮箱结果:
方法二:
转载:https://blog.youkuaiyun.com/qq_36502272/article/details/94778069
代码如下:
import zmail,os,base64
report_url=os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(file))),r’reports\result.html’)
report_pic_url=os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(file))),r’reports\result.jpg’)
#读取html报告
with open(report_url,‘r’,encoding=‘utf-8’) as f:
report_html=f.read()
#邮件内容和附件
mail={‘subject’:‘邮件主题’,‘content_text’:‘邮件内容’,‘content_html’:report_html,‘attachments’:[report_url,report_pic_url]}
#发送人邮件信息
server=zmail.server(‘20173535@qq.com’,‘yzfbrgil’,smtp_host=‘smtp.qq.com’,smtp_port=465)
#发送至收件人和抄送人
server.send_mail([‘wangl@xinrenlei.net’,‘61954991@qq.com’],mail,cc=[‘20173535@qq.com’])
备注:1、收件人既有163邮箱也有qq邮箱容易发生错误
2、163的端口号是465
===============================牛牛杂货店
====================修改一
=======源代码
import smtplib
from email.mime.text import MIMEText
email_host = 'smtp.163.com' #邮箱地址
email_user = 'xxxx@163.com' # 发送者账号
email_pwd = 'xxxx' # 发送者密码
maillist ='511402865@qq.com'
#收件人邮箱,多个账号的话,用逗号隔开
me = email_user
msg = MIMEText('邮件发送测试内容') # 邮件内容
msg['Subject'] = '邮件测试主题' # 邮件主题
msg['From'] = me # 发送者账号
msg['To'] = maillist # 接收者账号列表
smtp = smtplib.SMTP(email_host,port=25) # 连接邮箱,传入邮箱地址,和端口号,smtp的端口号是25
smtp.login(email_user, email_pwd) # 发送者的邮箱账号,密码
smtp.sendmail(me, maillist, msg.as_string())
# 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
smtp.quit() # 发送完毕后退出smtp
print ('email send success.')
====================修改二