久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

網頁爬蟲 - python+smtp發送郵件附件問題

瀏覽:138日期:2022-06-30 17:08:30

問題描述

文件是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.

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 伊川县| 平潭县| 稷山县| 水城县| 社旗县| 安仁县| 保定市| 邮箱| 东乡族自治县| 隆子县| 平罗县| 无棣县| 金乡县| 镇江市| 丰原市| 于都县| 晋中市| 白玉县| 金门县| 湾仔区| 龙山县| 龙里县| 澎湖县| 两当县| 朔州市| 嘉定区| 孟州市| 金湖县| 涟水县| 右玉县| 台湾省| 芒康县| 堆龙德庆县| 沂源县| 临湘市| 河源市| 象州县| 安溪县| 刚察县| 黄山市| 改则县|