发布新日志

  • python3发送邮件(yagmail)

    2018-01-30 17:58:15

    python3发送邮件(yagmail)

    # coding:utf-8

    import yagmail

    # 链接邮箱服务器
    yag = yagmail.SMTP(user="xxx@xx.com", password="xxx!!", host='smtp.xxx.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(['xxx@xx.com', 'xxxxxx@xx.com'], '发送附件', contents, ['test.html', 'logo.jpg', 'yagmal_test.txt'])

    #抄送
    # 邮箱正文  文本及附件
    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', '测试邮件', 'test.html', 'logo.jpg',
    'yagmal_test.txt']

    # 发送邮件
    yag.send(to='xx@xx.com', cc='xxx@xxx.com', subject='发送附件', contents=contents)
Open Toolbar