def book_msg(to_addr, book):
# TODO: Give a subject.
subject = ''
mobi_workshop_dir = '../../mobi_workshop/'
bookname = book+'.mobi'
msg = MIMEMultipart()
msg['From'] = mail_config['from_addr']
msg['To'] = to_addr
msg['Subject'] = Header(subject, 'utf-8').encode()
msg.attach(MIMEText('send with file...', 'plain', 'utf-8'))
# TODO: check if target is 0kb, if so, send_alert.
with open(mobi_workshop_dir+book+'.mobi', 'rb') as f:
mime = MIMEBase('*', '*/*', filename=bookname)
mime.add_header('Content-Disposition', 'attachment', filename=bookname)
mime.add_header('Content-ID', '<0>')
mime.add_header('X-Attachment-Id', '0')
mime.set_payload(f.read())
encoders.encode_base64(mime)
msg.attach(mime)
return msg
评论列表
文章目录