#!/usr/bin/env python3
#coding:utf-8
import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.utils import formataddr
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
sender = "xxx@163.com"
receivers = [sender,'xxx@kindle.cn,xxx@kindle.cn']
def email(filename):
msg = MIMEMultipart()
msg['From'] = formataddr(["Kindle 管理员", sender])
msg['To'] = formataddr(["kindle", receivers[0]])
msg['Subject'] = "电子书同步: %s" % filename
msg.attach(MIMEText(filename, 'plain', 'utf-8'))
att = MIMEApplication(open(filename, 'rb').read())
att.add_header(
'Content-Disposition',
'attachment',
filename=Header(filename, "utf-8").encode())
msg.attach(att)
try:
server = smtplib.SMTP("smtp.163.com")
server.login(sender, "xxxxx")
server.sendmail(sender, receivers, msg.as_string())
print("*邮件* %s 发送成功!" % filename)
except smtplib.SMTPException:
print("Error: 无法发送邮件")
import os
if __name__ == '__main__':
# email("hello")
# for root, dirs, files in os.walk("."):
files = os.listdir()
files = filter(lambda x:x.endswith(".mobi") or x.endswith(".epub") or x.endswith((".pdf")),files)
for filename in files:
email(filename)
利用 Python 一键推送电子书到 Kindle
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...