三行代码发送带附件邮件

2018-06-28  本文已影响6人  6c0fe9142f09

demo

pip install yagmail
import yagmail
def emailWithFile(bodyText,sendFileName):
    # qq邮箱的邮件发送需要获取SMTP密码,使用qq密码是不行的
    yag = yagmail.SMTP(user='565506019@qq.com', password='passwd', host='smtp.qq.com', port='465')
    body = u""+bodyText
    yag.send(to='565506019@qq.com', subject="环球财经-"+bodyText, contents=[body, sendFileName])

运行结果

emailWithFile("180621","····/yangshicaijing180621.aac")

参考文章

https://www.jianshu.com/p/3d1f6cc65630?from=singlemessage

上一篇 下一篇

猜你喜欢

热点阅读