網頁爬蟲 - 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('[email protected]','YYYYYY')msg=MIMEMultipart(’’)msg[’From’]='[email protected]'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’]='[email protected]'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. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題2. docker安裝后出現Cannot connect to the Docker daemon.3. css - 定位為absolute的父元素中的子元素 如何設置在父元素的下面?4. java - 請問在main方法中寫成對象名.屬性()并賦值,與直接參參數賦值輸錯誤是什么原因?5. java - Spring boot 讀取 放在 jar 包外的,log4j 配置文件,系統有創建日志文件,不寫入日志信息。6. mysql里的大表用mycat做水平拆分,是不是要先手動分好,再配置mycat7. java - socket類服務端如何防止被ddos攻擊?8. javascript - 圖片鏈接請求一直是pending狀態,導致頁面崩潰,怎么解決?9. python - beautifulsoup獲取網頁內容的問題10. 怎么用css截取字符?
