网页爬虫 - python+smtp发送邮件附件问题
问题描述
文件是txt或者word格式的,但是要求附件发送过去是pdf格式的,smpt有没有什么参数是可以设置的,我设置了_subtype='pdf',最后附件打开会报错,说不是一个pdf文件,打不开
import smtplibfrom email.mime.multipart import MIMEMultipartfrom email.mime.application import MIMEApplicationimport tracebackimport osserver=smtplib.SMTP()server.connect('smtp.163.com')server.login('XXXXXX@163.com','YYYYYY')msg=MIMEMultipart(’’)msg[’From’]='XXXXXX@163.com'msg[’Subject’]='opp'part = MIMEApplication(open('D:log.txt', ’rb’).read(),_subtype=’pdf’)#filetype='pdf'filetype = os.path.splitext('D:log.txt')[-1][1:]newfilename = ’resume’ + ’.’ + filetypepart.add_header(’Content-Disposition’, ’attachment’, filename=newfilename)msg.attach(part)msg[’To’]='TTTTTT@163.com'server.send_message(msg)
求解直接报filetype改成pdf也会文件报错
问题解答
回答1:SMTP is the protocol you are sending the completed email with, the MIME type is the content type of the attachment as declared in the email and the actual content type the file has. If you want to send a doc file as pdf you have to convert it first.
相关文章:
1. css3 - 请问一下在移动端CSS布局布局中通常需要用到哪些元素,属性?2. android - 使用vue.js进行原生开发如何进行Class绑定3. 网页爬虫 - python requests爬虫,如何post payload4. PHP能实现百度网盘的自动化么?5. node.js - 微信的自动回复问题6. javascript - 百度图片切换图片时url会改变,但无刷新,没用hash,IE8也支持,请问是用了什么技术?7. MySQL 水平拆分之后,自动增长的ID有什么好的解决办法?8. 我正在使用jsp / jstl / spring动态生成css和js。如何将此结果放置在头部的链接标签中。不在头部的脚本标签中9. angular.js - 各位大神们,你们混合开发,web方式中更推荐用什么框架呀? react?vue?angular?谢谢~10. mysql如何添加索引的时候指定索引方式
