yagmail库——简单发邮件

2018-03-20  本文已影响0人  学习编程好少年

项目主页:https://github.com/kootenpv/yagmail

  1. 安装
pip3 install yagmail
pip3 install keyring
  1. 简单例子
import yagmail
yag = yagmail.SMTP(user = 'xxx@163.com', password = 'xxx', host = 'smtp.163.com')
yag.send(to = 'xxx@163.com', subject = 'This is subject', contents = 'This is content')

注意:

  1. 给多个邮箱发邮件
yag.send(to = ['aa@163.com','bb@qq.com','cc@gmail.com'], 'subject', 'contents')
  1. 发送附件
yag.send(to = 'xxx@163.com', subject = 'subject', 
         contents = ['hello', 'C:\\Users\\Desktop\\test.txt'])

注意:如果邮件发送之后被退回,那么程序不会显示任何错误信息,但是发件人的邮箱会有退信邮件。

  1. 更多细节
yagmail.register('mygmailusername', 'mygmailpassword')

更多细节请参考项目主页。

上一篇 下一篇

猜你喜欢

热点阅读