python之yagmail库笔记

1. yagmail是啥

yagmail是给正常人用的,封装的比较彻底的一个python邮件库,发送接收邮件只需要几行代码,炒鸡简单。

2. 安装

使用pip安装,炒鸡简单:

pip install yagmail

3. 使用

发送也炒鸡简单,只需要几行即可:

import yagmail

if __name__ == '__main__':
    username = '**********'
    passwd = '**********'
    host = 'smtp.qq.com'
    port = '465'

    subject = '本周周报'
    contents = {'这是本周的周报,请批阅。', 'G:/test/我的照片.jpg'}

    mail = yagmail.SMTP(username, passwd, host, port)
    mail.send(to=['CC11001100@qq.com', 'CC11001100@qq.com'], subject=subject, contents=contents)

当to传入了一个列表、元组之类的时候表示发送给多个收件人,效果大概是这个样子的:

image

更多用法参考官方手册: https://github.com/kootenpv/yagmail

参考资料:

1. https://github.com/kootenpv/yagmail

.

原文地址:https://www.cnblogs.com/cc11001100/p/7842033.html