網(wǎng)頁(yè)爬蟲 - python+smtp發(fā)送郵件附件問(wèn)題
問(wèn)題描述
文件是txt或者word格式的,但是要求附件發(fā)送過(guò)去是pdf格式的,smpt有沒有什么參數(shù)是可以設(shè)置的,我設(shè)置了_subtype='pdf',最后附件打開會(huì)報(bào)錯(cuò),說(shuō)不是一個(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ò)
問(wèn)題解答
回答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. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????2. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)3. html按鍵開關(guān)如何提交我想需要的值到數(shù)據(jù)庫(kù)4. mysql取模分表與分表5. gvim - 誰(shuí)有vim里CSS的Indent文件, 能縮進(jìn)@media里面的6. HTML 5輸入框只能輸入漢字、字母、數(shù)字、標(biāo)點(diǎn)符號(hào)?正則如何寫?7. 跟著課件一模一樣的操作使用tp6,出現(xiàn)了錯(cuò)誤8. PHP類屬性聲明?9. objective-c - ios 怎么實(shí)現(xiàn)微信聯(lián)系列表 最好是swift10. javascript - 請(qǐng)教如何獲取百度貼吧新增的兩個(gè)加密參數(shù)
