網(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. javascript - vscode alt+shift+f 格式化js代碼,通不過(guò)eslint的代碼風(fēng)格檢查怎么辦。。。2. javascript - [js]為什么畫(huà)布里不出現(xiàn)圖片呢?在線等3. python - 如何判斷爬蟲(chóng)已經(jīng)成功登陸?4. html - vue項(xiàng)目中用到了elementUI問(wèn)題5. html5 - 有可以一次性把所有 css外部樣式轉(zhuǎn)為html標(biāo)簽內(nèi)style=" "的方法嗎?6. javascript - 如何將一個(gè)div始終固定在某個(gè)位置;無(wú)論屏幕和分辨率怎么變化;div位置始終不變7. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標(biāo)?8. javascript - 有什么比較好的網(wǎng)頁(yè)版shell前端組件?9. javascript - 這不是對(duì)象字面量函數(shù)嗎?為什么要new初始化?10. javascript - 求解答:實(shí)例對(duì)象調(diào)用constructor,此時(shí)constructor內(nèi)的this的指向?
