yagmail 实现发邮件

yagmail 可以简单的来实现自动发邮件功能。

安装

pip install yagmail

 

简单例子

import yagmail

#链接邮箱服务器
yag = yagmail.SMTP( user="user@126.com", password="1234", host='smtp.126.com')

# 邮箱正文
contents = ['This is the body, and here is just text http://somedomain/image.png',
            'You can find an audio file attached.', '/local/path/song.mp3']

# 发送邮件
mail.send(
    to=['123@qq.com','1255@qq.com'], #如果多个收件人的话,写成list就行了,如果只是一个账号,就直接写字符串就行to='123@qq.com'
    cc='735@qq.com',#抄送
    subject='学习发送邮件',#邮件标题
    contents='你好,你今天开心吗?',#邮件正文
    attachments=[r'd://log.txt', r'd://baidu_img.jpg'])#附件如果只有一个的话,用字符串就行,attachments=r'd://baidu_img.jpg'

yag.send('aaaa@126.com', '发送附件', contents, ["d://log.txt","d://baidu_img.jpg"])
#关闭
yag.close()

 总共四行代码搞定。

 

 

python之yagmail模块--小白博客

相关文章:

  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-10-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
相关资源
相似解决方案