io.py 文件源码

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

项目:pecos 作者: sandialabs 项目源码 文件源码
def _create_email_message(subject, body, recipient, sender, attachment=None):

    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['To'] = ', '.join(recipient)
    msg['From'] = sender

    if "</html>" in body.lower():
        content = MIMEText(body, 'html')
    else:
        content = MIMEText(body, 'plain')

    msg.attach(content)

    if attachment is not None:
        fp = open(attachment, "rb")  # Read as a binary file, even if it's text  
        att = MIMEApplication(fp.read())
        att.add_header('Content-Disposition', 'attachment', 
                       filename=os.path.basename(attachment))
        fp.close()
        msg.attach(att)

    return msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号