網(wǎng)頁(yè)爬蟲(chóng) - python+smtp發(fā)送郵件附件問(wèn)題
問(wèn)題描述
文件是txt或者word格式的,但是要求附件發(fā)送過(guò)去是pdf格式的,smpt有沒(méi)有什么參數(shù)是可以設(shè)置的,我設(shè)置了_subtype='pdf',最后附件打開(kāi)會(huì)報(bào)錯(cuò),說(shuō)不是一個(gè)pdf文件,打不開(kāi)
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)
求解直接報(bào)filetype改成pdf也會(huì)文件報(bào)錯(cuò)
問(wèn)題解答
回答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.
相關(guān)文章:
1. apache - 本地搭建wordpress權(quán)限問(wèn)題2. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????3. css3 - transition屬性當(dāng)鼠標(biāo)一開(kāi)的時(shí)候設(shè)置的時(shí)間不起作用4. 熱切期待朱老師的回復(fù),網(wǎng)頁(yè)視頻在線播放器插件配置錯(cuò)誤5. macos - mac下docker如何設(shè)置代理6. Android下,rxJava+retrofit 并發(fā)上傳文件和串行上傳文件的效率為什么差不多?7. angular.js - ng-grid 和tabset一起用時(shí),grid width默認(rèn)特別小8. javascript - web網(wǎng)頁(yè)版app返回上一頁(yè)按鈕在ios設(shè)備失效怎么辦?安卓上可以,代碼如下,請(qǐng)大神幫助,萬(wàn)分感謝。9. Whitelabel錯(cuò)誤頁(yè)面發(fā)生意外錯(cuò)誤(類型=未找到,狀態(tài)= 404)/WEB-INF/views/home.jsp10. java - Spring Mvc全局異常處理器@ControllerAdvice不起作用?
