mailing.py 文件源码

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

项目:CIDDS 作者: markusring 项目源码 文件源码
def addAttachments(msg):
    attachments = []
    lines = file_len("packages/mailing/attachments.txt")
    nb = random.randint(0, lines)
    for i in range(0, nb-1):
        rand = random.randint(1, lines)
        att = linecache.getline("packages/mailing/attachments.txt", rand).replace ("\n", "")
        attachments.append(att)
    if nb > 0:
        for f in attachments or []:
            with open(f, "rb") as fil:
                part = MIMEBase('application', "octet-stream")
                part.set_payload(fil.read())
                Encoders.encode_base64(part)
                part.add_header('Content-Disposition', 'attachment; filename="%s"' %f)
                msg.attach(part)
        echoC(__name__, "Attachments attached")
    else:
        echoC(__name__, "No attachments")
    return msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号