python发送邮件

实现python 服务器发送邮件功能
#
Author:rendelei # !/usr/bin/python # -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header sender = '发送人' receiver = ['接收邮箱'] smtpserver = 'smtp邮箱' message = MIMEMultipart() message['From'] = Header("python_sever", 'utf-8') message['To'] = Header("test", 'utf-8') subject = 'Python SMTP test' message['Subject'] = Header(subject, 'utf-8') message.attach(MIMEText('This a Python test email.....', 'plain', 'utf-8')) att1 = MIMEText(open('test.txt', 'rb').read(), 'base64', 'utf-8') att1["Content-Type"] = 'application/octet-stream' att1["Content-Disposition"] = 'attachment; filename="test.txt"' message.attach(att1) smtp = smtplib.SMTP() smtp.connect(smtpserver) smtp.sendmail(sender, receiver, message.as_string()) smtp.quit()

 

posted @ 2017-06-28 17:41  伊川草  阅读(102)  评论(0)    收藏  举报