網(wǎng)頁(yè)爬蟲 - python+smtp發(fā)送郵件附件問題
問題描述
文件是txt或者word格式的,但是要求附件發(fā)送過去是pdf格式的,smpt有沒有什么參數(shù)是可以設(shè)置的,我設(shè)置了_subtype='pdf',最后附件打開會(huì)報(bào)錯(cuò),說不是一個(gè)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)
求解直接報(bào)filetype改成pdf也會(huì)文件報(bào)錯(cuò)
問題解答
回答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. python - 爬蟲模擬登錄后,爬取csdn后臺(tái)文章列表遇到的問題2. python bottle跑起來以后,定時(shí)執(zhí)行的任務(wù)為什么每次都重復(fù)(多)執(zhí)行一次?3. javascript - angular使從elastichearch中取出的文本高亮顯示,如圖所示4. 前端 - 誰(shuí)來解釋下這兩個(gè) CSS selector 區(qū)別5. javascript - vue2如何獲取v-model變量名6. html5 - HTML代碼中的文字亂碼是怎么回事?7. javascript - ios返回不執(zhí)行js怎么解決?8. javascript - 求幫助 , ATOM不顯示界面!!!!9. mysql - 分庫(kù)分表、分區(qū)、讀寫分離 這些都是用在什么場(chǎng)景下 ,會(huì)帶來哪些效率或者其他方面的好處10. 視頻文件不能播放,怎么辦?
