email_with_mako.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:web_develop 作者: dongweiming 项目源码 文件源码
def gen_msg(content, subject, attachments, nick_from=None, nick_to='??'):
    if nick_from is None:
        nick_from = FROM_ADDR
    msg = MIMEMultipart()
    msg['From'] = _format_addr('{} <{}>'.format(nick_from, FROM_ADDR))
    msg['To'] = _format_addr('{} <{}>'.format(nick_to, TO_ADDRS))
    msg['Subject'] = Header(subject)
    msg.attach(MIMEText(content, 'html', 'utf-8'))

    for attachment in attachments:
        attach = MIMEText(open(attachment, 'rb').read(), 'base64', 'utf-8')
        attach['Content-Type'] = 'application/octet-stream'
        attach['Content-Disposition'] = 'attachment; filename="{}"'.format(
            os.path.basename(attachment))
        msg.attach(attach)
    return msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号