zoukankan      html  css  js  c++  java
  • python之yagmail模块--小白博客

    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()

     总共四行代码搞定。

     

  • 相关阅读:
    poj3016
    BZOJ2560 串珠子
    HAOI 2009 逆序对数列
    BJOI2012 最多的方案
    ZJOI2008 生日聚会
    ZJOI2008 骑士
    SCOI2003 严格N元树
    SDOI2010 地精部落
    USACO Section 3.2 Stringsobits
    JLOI2013 卡牌游戏
  • 原文地址:https://www.cnblogs.com/zhou2019/p/10600087.html
Copyright © 2011-2022 走看看