网页爬虫 - 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. java - Ckeditor上传图片时出现mutipartRequest 转换异常2. python - Django ManyToManyField 字段数据在 admin后台 显示不正确,这是怎么回事?3. javascript - 怎样去除数组里的几个值,只提供该数组的下标的话4. javascript - vue-cli热更新的问题【webpack配置】5. 为什么span的color非要内联样式才起作用?6. 老师无限级分类有点难哟 不好理解7. php由5.3升级到5.6后,登录网站,返回的是php代码,不是登录界面,各位大神有知道的吗?8. mysql 能不能创建一个 有列级函数 的联合视图?9. node.js - webpack required打包问题10. 提示内部服务错误什么问题

网公网安备