網頁爬蟲 - 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('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)
求解直接報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. mysql - Sql union 操作2. php - 生產環境下,給MySQL添加索引,修改表結構操作,如何才能讓線上業務不受影響?3. javascript - 按鈕鏈接到另一個網址 怎么通過百度統計計算按鈕的點擊數量4. android - 安卓做前端,PHP做后臺服務器 有什么需要注意的?5. java - Mybatis 數據庫多表關聯分頁的問題6. 急急急!!!求大神解答網站評論問題,有大神幫幫小弟嗎7. mysql - 僅僅只是把單引號與反斜杠轉義不用prepare statement能否避免sql注入?8. 新入手layuiadmin,部署到tp中。想用php自已寫一個后臺管理系統。9. mysql在限制條件下篩選某列數據相同的值10. mysql 獲取時間函數unix_timestamp 問題?
