源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

python发送邮件的实例代码(支持html、图片、附件)

  • 时间:2020-07-18 04:59 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python发送邮件的实例代码(支持html、图片、附件)
第一段代码:
[url=http://www.python.org]    </p>   </body> </html> """ # Record the MIME types of both parts - text/plain and text/html. part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, in this case # the HTML message, is best and preferred. msg.attach(part1) msg.attach(part2) #构造附件 att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename="1.jpg"' msg.attach(att) smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit()
基于SSL的邮件
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部