python 脚本发送邮件
#!/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()