一、Python发送邮件

import smtplib
from email.mime.text import MIMEText
def send(email_to,title,content):
msg = MIMEText(content,"plain","utf-8")
froms = "1257063655@qq.com"
to_list = email_to.replace("\n","").split(",")
print(to_list)
msg["Subject"] = title # 传参
msg["From"] = froms # 发件人
msg["To"] = email_to # 收件人
server = smtplib.SMTP_SSL("smtp.qq.com",)
server.login(froms,"oylltctlxijogdbb")
server.sendmail(froms,to_list,msg.as_string())
# 发送人,收件人列表, # 内容
print("发送成功")
server.quit() title = "邮件报警测试"
content = """系统磁盘空间或内存可能快要满了"""
email_to = """
@qq.com
"""
if __name__ == '__main__':
send(email_to,title,content)

二、zabbix实现邮件报警

1)添加python脚本文件

#! /usr/bin/env python3
# -*- coding: utf- -*-
import smtplib
import sys
from email.mime.text import MIMEText
def send_mail(email_to,title,content):
msg = MIMEText(content,"plain","utf-8")
froms = "1257063655@qq.com"
to_list = email_to.replace("\n","").split(",")
print(to_list)
msg["Subject"] = title # 传参
msg["From"] = froms # 发件人
msg["To"] = email_to # 收件人
server = smtplib.SMTP_SSL("smtp.qq.com",)
server.login(froms,"oylltctlxijogdbb")
server.sendmail(froms,to_list,msg.as_string())
server.quit() if __name__ == '__main__':
send_mail(sys.argv[], sys.argv[], sys.argv[])

send_email.py

2) 使用shell脚本去调用python脚本来进行发送邮件

[root@zabbix alertscripts]# cat send_email.sh
#!/bin/sh
/usr/bin/python3 /usr/local/zabbix/alertscripts/send_email.py $ $ $

[root@zabbix alertscripts]# chmod o+x send_email.sh

163邮箱测试

from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import logging
import smtplib def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr)) from_addr = 'nick1236xx@163.com'
password = 'dasb1234' # 授权码 # 输入SMTP服务器地址:
smtp_server = 'smtp.163.com' def sendmail(to_addr, link, secure=True):
title = '<html><body><h3>亲爱的<a data-auto-link="1" href="mailto:%s" target="_blank">%s</a>,您好:</h3>' % (to_addr, to_addr)
reset = "<div style = 'padding-left:55px;padding-right:55px;font-family:'微软雅黑','黑体',arial;font-size:14px;'>重置密码</div>"
body = '<p>请点击以下链接进行重置密码 <a href="%s">%s</a></p>' % (link, reset)
tail = '如果您并不是Awesome用户,可能是其他用户误输入了您的邮箱地址。</body></html>'
html = title + body + tail
msg = MIMEText(html, 'html', 'utf-8')
# 发送地址格式 都需要编码
msg['From'] = _format_addr('Awesome Python Webapp <%s>' % from_addr)
msg['To'] = _format_addr('亲爱的用户 <%s>' % to_addr)
msg['Subject'] = Header('重置密码', 'utf-8').encode()
try:
if secure:
server = smtplib.SMTP_SSL(smtp_server, ) # 启用SSL发信, 端口一般是465
else:
server = smtplib.SMTP(smtp_server, )
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()
except smtplib.SMTPException as e:
logging.error('sendemail:%s' % e) if __name__ == '__main__':
# 输入收件人地址:
to_addr = '150648003@qq.com'
sendmail(to_addr, 'http://www.baidu.com', True)

python发送邮箱的更多相关文章

  1. python发送邮箱的小项目

    import smtplibfrom email.mime.text import MIMEText receiver = input('输入接受者邮箱\n')subject = input('输入标 ...

  2. python 发送附件至邮箱

    python 发送附件至邮箱 import smtplibfrom email.MIMEText import MIMETextfrom email.MIMEMultipart import MIME ...

  3. 利用Python+163邮箱授权码发送带附件的邮件

    背景 前段时间写了个自动爬虫的脚本,定时在阿里云服务器上执行,会从某个网站上爬取链接保存到txt文本中,但是脚本不够完善,我需要爬虫完毕之后通过邮件把附件给我发送过来,之前写过一个<利用Pyth ...

  4. 使用python发送163邮件 qq邮箱

    使用python发送163邮件 def send_email(title, content): import smtplib from email.mime.multipart import MIME ...

  5. python给邮箱发送消息

    首先要用到两个模块  并且大同你的发送邮箱smtp 最开始测试没打通了好久 smtplib是提供邮箱smtp服务, email是提供你发送消息的格式之类服务 import smtplib from e ...

  6. 【转】Oracle AWR 报告 每天自动生成并发送邮箱 Python脚本(一)

    Oracle 的AWR 报告能很好的提供有关DB性能的信息. 所以DBA 需要定期的查看AWR的报告. 有关AWR报告的说明参考: Oracle AWR 介绍 http://blog.csdn.net ...

  7. tornado web高级开发项目之抽屉官网的页面登陆验证、form验证、点赞、评论、文章分页处理、发送邮箱验证码、登陆验证码、注册、发布文章、上传图片

    本博文将一步步带领你实现抽屉官网的各种功能:包括登陆.注册.发送邮箱验证码.登陆验证码.页面登陆验证.发布文章.上传图片.form验证.点赞.评论.文章分页处理以及基于tornado的后端和ajax的 ...

  8. 转: Oracle AWR 报告 每天自动生成并发送邮箱

    原贴地址:http://www.cnblogs.com/vigarbuaa/archive/2012/09/05/2671794.html Oracle AWR 介绍http://blog.csdn. ...

  9. [Python] 发送email的几种方式

    python发送email还是比較简单的,能够通过登录邮件服务来发送,linux下也能够使用调用sendmail命令来发送,还能够使用本地或者是远程的smtp服务来发送邮件,无论是单个,群发,还是抄送 ...

随机推荐

  1. lecune入门示例

    注意:本示例中的lucene版本需在jdk7以上使用. 一.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...

  2. kubernetes学习笔记之十三:基于calico的网络策略入门

    一..安装calico [root@k8s-master01 ~]# kubectl apply -f https://docs.projectcalico.org/v3.3/getting-star ...

  3. SpringMVC 启动流程

    首先看一下Web应用部署初始化过程 (Web Application Deployement),官方文档说明: Web Application Deployment When a web applic ...

  4. window.open() 打开的子页面 往主页面传参问题

    <!--主页面的代码--><!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

  5. ORACLE重装之后恢复数据库,相当于sqlserver的附加数据库

    在开发机器上经常会遇到重装系统的问题,重装之前如果ORACLE没有及时备份的话重装之后就纠结了,数据还原很头疼. 各种娘中只能找到一些ORACLE安装与重装系统前目录相同的解决办法,目录不同就没招了. ...

  6. tensorflow-yolo3系列配置文章汇总

    yolo 网络讲解 https://blog.csdn.net/m0_37192554/article/details/81092514 https://blog.csdn.net/guleileo/ ...

  7. orcal - 单行函数

    虚拟表:dual 转大写 select UPPER('hellow') from dual; 转小写 select lower(ename) from emp; cmd 输入数据 select * f ...

  8. web监控,if 语句

    对页面的测试  curl "] #if [`curl -I http://10.0.0.7 &>/dev/null|head -l|grep 200|wc -l` -eq 1] ...

  9. Python : *args和**kwargs是什么东东呢?

    def foo(*args, **kwargs): print 'args = ', args print 'kwargs = ', kwargs print '------------------- ...

  10. java导出excel模板数据

    Java导出excel数据模板,这里直接贴代码开发,流程性的走下去就是步骤: String[] colName=new String[]{"期间","科目代码" ...