python使用yagmail发送邮件

使用yagmail发送普通邮件的话,只需要几行代码

sender = '[email protected]'
password = 'xxx'
res = '[email protected]'

yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com', smtp_ssl=True)
content = 'hello world'
yag.send(to=res, subject='测试发邮件', contents=content)

发送带有附件和网页的邮件

import yagmail, os

sender = '[email protected]'
password = 'xxx'
res = '[email protected]'

html = """



    
    Title


    

这是一个测试邮件

""" yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com', smtp_ssl=True) contents = ['这是一个测试邮件', html, os.path.join(os.path.dirname(__file__), '613240.jpg')] yag.send(to=res, subject='测试发邮件', contents=contents) print('发送成功')

 

你可能感兴趣的:(python)