您的位置:首页 > 编程语言 > Python开发

python 脚本发送邮件

2014-01-13 15:56 453 查看
#!/usr/bin/env python
#coding: utf-8
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
#import stmp_mail
sender = 'hadoop520@126.com'
receiver ='hello@126.com'
subject = '数据测试'
smtpserver = 'smtp.126.com'
username = 'hadoop520'
password = '111111'
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'test message'
#构造附件
att = MIMEText(open('/apps/aspbi/shenshuxin/1.csv', 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="数据.csv"'
msgRoot.attach(att)
smtp = smtplib.SMTP()
smtp.connect('smtp.126.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: