美文网首页
python利用yagmail发送邮件

python利用yagmail发送邮件

作者: 西电大侠 | 来源:发表于2019-05-03 10:50 被阅读0次

    python发送邮件是利用smtplib库,之前操作少玩有点浮躁,找到一个更简单的yagmail。
    下面说说具体怎么写
    1、安装
    pip install -i https://pypi.python.org/pypi yagmail

    2、安装好后
    写程序测试

    if __name__ == "__main__":
        import yagmail
        #链接邮箱服务器
        yag = yagmail.SMTP( user="emailname@163.com", password="授权码", host='smtp.163.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']
        # 发送邮件
        yag.send('812865052@qq.com', 'subject', contents)
    

    有一个点需要注意,password需要填163邮箱的授权码,具体如何生成授权码,可以Google。
    如果你是填的邮箱密码,可能报错


    image.png

    相关文章

      网友评论

          本文标题:python利用yagmail发送邮件

          本文链接:https://www.haomeiwen.com/subject/oeyanqtx.html