網(wǎng)頁爬蟲 - python+smtp發(fā)送郵件附件問題
問題描述
文件是txt或者word格式的,但是要求附件發(fā)送過去是pdf格式的,smpt有沒有什么參數(shù)是可以設(shè)置的,我設(shè)置了_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.
相關(guān)文章:
1. 人工智能 - python 機器學(xué)習(xí) 醫(yī)療數(shù)據(jù) 怎么學(xué)2. python - oslo_config3. 請教一個mysql去重取最新記錄4. python - 請問這兩個地方是為什么呢?5. Python處理Dict生成json6. 急急急!?。∏蟠笊窠獯鹁W(wǎng)站評論問題,有大神幫幫小弟嗎7. javascript - 按鈕鏈接到另一個網(wǎng)址 怎么通過百度統(tǒng)計計算按鈕的點擊數(shù)量8. python2.7 - python 正則前瞻 后瞻 無法匹配到正確的內(nèi)容9. 大家都用什么工具管理mysql數(shù)據(jù)庫?10. mysql - Sql union 操作
