網(wǎng)頁爬蟲 - 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. boot2docker無法啟動(dòng)2. 關(guān)于docker下的nginx壓力測(cè)試3. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類4. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.5. mac里的docker如何命令行開啟呢?6. node.js - antdesign怎么集合react-redux對(duì)input控件進(jìn)行初始化賦值7. 為什么我ping不通我的docker容器呢???8. 老師,按tab鍵不起作用怎么回事9. docker鏡像push報(bào)錯(cuò)10. dockerfile - 為什么docker容器啟動(dòng)不了?

網(wǎng)公網(wǎng)安備