import smtplib from email.mime.text import MIMEText from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication if __name__ == '__main__': fromaddr = '[email protected]' password = 'xxxxxx' toaddrs = ['[email protected]', '[email protected]'] #构建文字内容 content = 'hello, this is email content.' textApart = MIMEText(content,'plain','utf-8') #读取本地图片 imageFile = 'D:\计算机二级\dog.jpg' imageApart = MIMEImage(open(imageFile, 'rb').read(), imageFile.split('.')[-1]) imageApart.add_header('Content-Disposition', 'attachment', filename=imageFile) #读取本地文档 pdfFile = 'D:\计算机二级\chicago.csv' pdfApart = MIMEApplication(open(pdfFile, 'rb').read()) pdfApart.add_header('Content-Disposition', 'attachment', filename=pdfFile) m = MIMEMultipart() m.attach(textApart) m.attach(imageApart) m.attach(pdfApart) m['Subject'] = 'title' #发送邮件 try: server = smtplib.SMTP('smtp.qq.com',25) server.login(fromaddr,password) server.sendmail(fromaddr, toaddrs, m.as_string()) print('success') server.quit() except smtplib.SMTPException as e: print('error:',e) #打印错误

 

文章来源于网络,如有侵权请联系站长QQ61910465删除
本文版权归qu快排seo www.sEoguRuBlog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ√61910465