網(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. mysql - 在不允許改動數(shù)據(jù)表的情況下,如何優(yōu)化以varchar格式存儲的時間的比較?2. javascript - Img.complete和img.onload判斷圖片加載完成有什么區(qū)別?3. java中返回一個對象,和輸出對像的值,意義在哪兒4. mysql 為什么主鍵 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?5. css3 - 純css實現(xiàn)點擊特效6. docker網(wǎng)絡(luò)端口映射,沒有方便點的操作方法么?7. css - 網(wǎng)頁div區(qū)塊 像蘋果一樣可左右滑動 手機與電腦8. 安全性測試 - nodejs中如何防m(xù)ySQL注入9. javascript - 關(guān)于apply()與call()的問題10. python - 在sqlalchemy中獲取剛插入的數(shù)據(jù)id?
