阅读本文需要5.5分钟
今天我们就说说用Python给kindle推送电子书
第三方库:
import smtplib import email.mime.multipart import email.mime.text from email.mime.text import MIMEText import tkinter.filedialog from tkinter import * import tkinter.messagebox
核心代码:
一:发送阶段
def send(): msg = email.mime.multipart.MIMEMultipart() msgFrom = 'xxxxxxx@163.com' # SMTP的邮箱 msgTo = 'xxxxx@kindle.cn' # 亚马逊的邮箱 smtpSever = 'smtp.163.com' # SMTP的服务器 smtpPort = '25' # 端口号 sqm = 'xxxxxxxx' # 邮箱密码 msg['from'] = msgFrom msg['to'] = msgTo msg['subject'] = '[Kindle]Martin' content = ''' Dear Martin, Please check this book. Auto send program ''' txt = email.mime.text.MIMEText(content) msg.attach(txt) # 附件 # path=file_path # file_name=path+name+'.xlsx' att = MIMEText(open(file_path, 'rb').read(), 'base64', 'gb2312') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename=' + file_path msg.attach(att) # smtp = smtplib smtp = smtplib.SMTP() smtp.connect(smtpSever, smtpPort) smtp.login(msgFrom, sqm) smtp.sendmail(msgFrom, msgTo, str(msg))
二. 文件格式:
def callback1(): global file_path file_path = tkinter.filedialog.askopenfilename(initialdir="C:/Users/Martin/Downloads", filetypes=(("亚马逊电子书格式", "*.mobi*"), ("Excel 97-2003 工作簿", "*.xls"), ("pdf格式", "*.pdf*"))) t.insert('insert', file_path)
运行截图:
对于不了解Python的人来说,其实这样还是比较麻烦,最好的办法是直接发邮件或者连接数据线。当然此教程是学习经验和思路。若想要完整的源码,后台请回复[kindle]即可获取。
end