python 发邮件:sina普通版 | zabbix版本

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from  email.mime.text  import  MIMEText
from  email.header  import  Header
from  smtplib  import  SMTP_SSL
 
 
def  send_mail(sender_sina = ' ',pwd=' ',receiver=' ',mail_title=' ',mail_content=' '):
     # 邮箱smtp服务器
     host_server  =  'smtp.sina.com'
     sender_sina_mail  =  sender_sina + '@sina.com'
     #ssl登录
     smtp  =  SMTP_SSL(host_server)
     #set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
     smtp.set_debuglevel( 0 )
     smtp.ehlo(host_server)
     smtp.login(sender_sina, pwd)
     msg  =  MIMEText(mail_content,  "plain" 'utf-8' )
     msg[ "Subject" =  Header(mail_title,  'utf-8' )
     msg[ "From" =  sender_sina_mail
     msg[ "To" =  receiver
     smtp.sendmail(sender_sina_mail, receiver, msg.as_string())
     smtp.quit()
send_mail( "hequan2011" , "密码" , "hequan2011@sina.com" , "标题" , '内容' )


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
#coding:utf-8
from  email.mime.text  import  MIMEText
from  email.header  import  Header
from  smtplib  import  SMTP_SSL
import  sys
 
 
def  send_mail(sender_sina = ' ',pwd=' ',receiver=' ',mail_title=' ',mail_content=' '):
     host_server  =  'smtp.sina.com'
     sender_sina_mail  =  sender_sina + '@sina.com'
     #ssl登录
     smtp  =  SMTP_SSL(host_server)
     #set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
     smtp.set_debuglevel( 0 )
     smtp.ehlo(host_server)
     smtp.login(sender_sina, pwd)
     try :
         msg  =  MIMEText(mail_content,  "plain" 'utf-8' )
         msg[ "Subject" =  Header(mail_title,  'utf-8' )
         msg[ "From" =  sender_sina_mail
         msg[ "To" =  receiver
         smtp.sendmail(sender_sina_mail, receiver, msg.as_string())
         smtp.quit()
         print ( "发送成功" )
         return   True
     except   Exception as e :
         print ( "发送失败:" ,e)
         return  False
         
if  __name__ = = "__main__" :
     #send_mail("hequan2011","密码","hequan2011@sina.com","标题",'内容')
     send_mail( "hequan2011" "密码" , sys.argv[ 1 ], sys.argv[ 2 ], sys.argv[ 3 ])









本文转自 295631788 51CTO博客,原文链接:http://blog.51cto.com/hequan/1939844,如需转载请自行联系原作者
目录
相关文章
|
2月前
|
存储 安全 网络安全
手把手教你使用Python轻松搞定发邮件
手把手教你使用Python轻松搞定发邮件
56 0
|
3月前
|
测试技术 程序员 数据库
Python 3.9 beta2 版本发布了,看看这 7 个新的 PEP 都是什么?
Python 3.9 beta2 版本发布了,看看这 7 个新的 PEP 都是什么?
30 0
|
3月前
|
安全 小程序 数据安全/隐私保护
aes加密算法python版本
aes加密算法python版本
41 0
|
3月前
|
Python
Python 3.10 版本采纳了首个 PEP,中文翻译即将推出
Python 3.10 版本采纳了首个 PEP,中文翻译即将推出
18 3
|
3月前
|
开发者 Python
开发者请注意:Python2 的最后版本将于 4 月发布,但它确实是在 1 月 1 日就寿命终止了!
开发者请注意:Python2 的最后版本将于 4 月发布,但它确实是在 1 月 1 日就寿命终止了!
28 1
|
3月前
|
机器学习/深度学习 PyTorch 算法框架/工具
Python冷知识:如何找出新版本增加或删除了哪些标准库?
Python冷知识:如何找出新版本增加或删除了哪些标准库?
27 0
|
3天前
|
Python
conda升级python版本
conda升级python版本
|
3天前
|
Linux API Python
【python】如何通过python来发邮件,各种发邮件方式详细解析
【python】如何通过python来发邮件,各种发邮件方式详细解析
|
7天前
|
开发者 Python
six,一个神奇的 Python 版本兼容工具库!
six,一个神奇的 Python 版本兼容工具库!
19 4
|
7天前
|
Ubuntu Python
ubuntu升级Python版本
现在,你已成功升级了Python版本并可以使用新版本进行开发和运行程序。
24 1

推荐镜像

更多