【python 邮件脚本】胸怀万里世界, 放眼无限未来。这篇文章主要讲述python 邮件脚本相关的知识,希望能为你提供帮助。
#!/usr/bin/python
# -*- coding: UTF-8 -*-import smtplib
import os
import json
import commands
from smtplib import SMTP_SSL
from email.mime.text import MIMEText#salt执行返回结果
def salt_result():
salt = commands.getoutput("cmd")
lines = salt.split(\'\\n\')
salt_new = {}for i in lines:
salt_json = eval(i)
num = salt_json.values()
len_num = len(list(num)[0])
if len_num >
7:
for key, values in salt_json.items():
salt_new[key] = str(values).split(\'\\n\')salt_res = json.dumps(salt_new)
return salt_res
#发送邮件
def sendMail(message,Subject,sender_show,recipient_show,to_addrs,cc_show=\'\'):user = \'用户名\'
password = \'密码\'
mail_host = \'smtp.exmail.qq.com\'msg = MIMEText(message, \'plain\', _charset="utf-8")
msg["Subject"] = Subject
msg["from"] = sender_show
msg["to"] = recipient_show
msg["Cc"] = cc_showtry:
smtpObj = smtplib.SMTP_SSL(mail_host)
smtpObj.connect(mail_host, 465)
smtpObj.login(user,password)
smtpObj.sendmail(user,to_addrs=to_addrs.split(\',\'), msg=msg.as_string())
smtpObj.quit()
print "邮件发送成功"
except smtplib.SMTPException:
smtpObj.quit()
print "Error: 无法发送邮件"if __name__ ==\'__main__\':
message = salt_result()
#print message
Subject = \'主题\'
sender_show = \'发送者\'
recipient_show = \'接收者\'
to_addrs = \'接收者\'
sendMail(message,Subject,sender_show,recipient_show,to_addrs)
推荐阅读
- VPS服务器性能一键测试脚本_IP路由/CPU基准/内存读取/下载上传速率测试脚本
- 看动画学算法之:doublyLinkedList
- 简单好用的文件实时监控工具——WGCLOUD
- 甲骨文云服务器一键修改root密码一键修改root密码
- 国庆出游神器(魔幻黑科技换天造物,让vlog秒变科幻大片!)
- 5G时代
- linux线上CPU100%排查
- 9.20-9.30博客精彩回顾
- 使用自定义数据源配置虚拟实体