代码如下
def send_attachment_kd(filename,toName,fromName,username,password):
msg = MIMEMultipart()
msg['Subject'] = 'convert'
msg['From'] = "username"+"<"+fromName+">"
msg['To'] = toName
part = MIMEBase('application', "octet-stream")
#fpath=os.path.join(KINDLE_DIR,filename)
filename_txt=filename+".txt"
#print filename_txt.decode('utf-8'
filecontent=open(filename_txt.decode('utf-8'),'r').read()
part.set_payload(filecontent)
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="Book.txt"')
msg.attach(part)
try:
server=smtplib.SMTP()
server.connect('smtp.qq.com')
server.login(username,password)
server.sendmail(msg['From'],toName,msg.as_string())
server.quit()
print "Send successfully"
except Exception,e:
print "Error"
print str(e)
在qq邮箱里面的发送箱可以看到我发送的邮件以及附件,没有乱码和不对的地方,可是我的kindle却一直都没有收到推送,请问有人写过相关的代码吗??
经过测试,发现是qq邮箱的问题。
全部源码链接:
python推送知乎文章到kindle
gtihub: https://github.com/Rockyzsu/zhihuToKindle
黄舟2017-04-17 16:37:08
After testing, it was found that it was a problem with the qq mailbox.
Full source code link: (regularly updated with new features)
http://30daydo.com/article/7
gtihub: https://github.com/Rockyzsu/z...
黄舟2017-04-17 16:37:08
Brother, please tell me, I developed it using Node. It's probably a problem of getting stuck in the mailbox and sending attachments that don't exist. Also cut the mailbox. I didn't run this complete version of yours. But I looked at the general idea and I have the same idea. I don’t know how you solve the attachment problem.
Let me tell you my situation.
1. The sending email address is certified.
2. Change to NetEase 163
3. If you send the same program to a small account, you will receive the attachment normally.
4. The cloud link is not saved when the mailbox storage has been set up
5. The content sent is a mobi file of less than 1MB downloaded before, which is guaranteed to be open and read.