前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python 编写自动发送邮件脚本

Python 编写自动发送邮件脚本

作者头像
简单、
发布2018-07-18 15:30:42
5720
发布2018-07-18 15:30:42
举报

弃用,超级超级超级简洁,超级超级厉害的第三方 ->见文章->

   #-*- encoding: utf-8 -*-
import os, sys
import smtplib
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText




mailInfo = {
    "from": "xxxxxxxx@qq.com",
    "to": "xxxxxxx@163.com",
    "hostname": "smtp.qq.com",
    "username": "xxxxxxx@qq.com",
    "password": "这里的密码是写你开启smtp服务生成的密码",
    "mailsubject": "安全警告",
    "mailtext": "Your ssh is error ",
    "mailencoding": "utf-8"
}

if __name__ == '__main__':
    smtp = SMTP_SSL(mailInfo["hostname"])
    smtp.set_debuglevel(1)
    smtp.ehlo(mailInfo["hostname"])
    smtp.login(mailInfo["username"],mailInfo["password"])

    
    msg = MIMEText(mailInfo["mailtext"],"text",mailInfo["mailencoding"])
    msg["Subject"] = Header(mailInfo["mailsubject"],mailInfo["mailencoding"])
    msg["from"] = mailInfo["from"]
    msg["to"] = mailInfo["to"]
    smtp.sendmail(mailInfo["from"], mailInfo["to"], msg.as_string())

    smtp.quit()

配合ssh登录判别脚本,实现警报发送邮件功能!

如果异地登录,发送报警邮件!

Tags: None

Archives QR Code

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档