网页爬虫 - 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. angular.js - react的redux和vue的vuex,angular呢2. javascript - 我写的href跳转地址不是百度,为什么在有的机型上跳转到百度了,有的机型跳转正确3. angular.js - vue/react 渲染内容抖动4. 新手学习vue和node.js的困惑5. python socket 如何接收tcp/ip byte 格式的数据?6. html - 自学php 遇到代码不执行直接在网页上显示 望各位大神不吝赐教7. python - beautifulSoup4 .select(’.bnrName’) 取不到到 text 文字8. 与远程浏览器通信时出错。它可能已经死了。Selenium Web驱动程序9. html - node-module文件有两个在我的项目文件里10. angular.js - webstorm angular 语法没有错误,但有红色波浪线警告?
