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
评论列表
文章目录