#windows系统
pip install yagmail
#苹果或linux系统
pip3 install yagmail
- 导入yagmail库及配置邮箱(以腾讯企业邮箱为例)
import yagmail
#链接邮箱服务器
yag = yagmail.SMTP( user="邮箱", password="授权码", host='smtp.exmail.qq.com')
# 发送邮件
yag.send(to = ['邮箱1','邮箱2'],
subject= '邮件主题',
contents = '内容',
attachments=[r'附件.xlsx'])
#关闭
yag.close()
如果报错提示utf-8,可能是因为电脑名称设置为中文,改成字母即可
如果提示503错误,可能是授权码写成了邮箱密码
import yagmail
#链接邮箱服务器
yag = yagmail.SMTP( user="邮箱", password="授权码", host='smtp.exmail.qq.com')
# 发送邮件
yag.send(to = ['邮箱1','邮箱2'],
subject= '邮件主题',
contents = "
<h3>《题都城南庄》</h3>\n
<font size=1 color='red'>去年今日此门中,</font>\n
<font size=1 color='red'>人面桃花相映红。</font>\n
<font size=1 color='red'>人面不知何处去,</font>\n
<font size=1 color='red'>桃花依旧笑春风。</font>
",
attachments=[r'附件.xlsx'])
#关闭
yag.close()
网友评论