简易发送邮件(仅限普通文本,发送邮箱需开启smtp),发送邮件smtp,若发送到139邮箱可通知
简易发送邮件(仅限普通文本,发送邮箱需开启smtp),发送邮件smtp,若发送到139邮箱可通知
若发送到139邮箱可通知手机,自动给手机发送短信
import smtplib#easy send email, only can send plain textfrom email.mime.text import MIMETextfrom smtplib import SMTPHeloError, SMTPAuthenticationError, SMTPHeloError, SMTPSenderRefused#easy send email, only can send plain textdef sendmail(target, subject, content) : msg = MIMEText(content) from_addr = "orighost@qq.com" to_addr = target msg['Subject'] = subject msg['From'] = from_addr msg['To'] = to_addr try: s = smtplib.SMTP('smtp.qq.com') s.login('orighost', '××××××') s.sendmail(from_addr, to_addr, msg.as_string()) except SMTPHeloError: print 'Error: Can not connect server.' return 1 except SMTPAuthenticationError: print 'Error: Username or password is not correct.' return 1 except SMTPHeloError: print 'Error: Can not deliver to target host.' return 1 except SMTPSenderRefused: print 'Error: The target server don\\'t accept you from_addr' return 1 except: print "Send failed" return 1 pass finally: s.quit() print "Send success." return 0if __name__ == "__main__": sendmail("orighost@qq.com", "hello", "welcome to use the email.")#该片段来自于http://byrx.net
相关内容
- 远程登录多台服务器执行其上脚本,远程登录多台,#!
- ConfigParser ? 配置文件值传递,,例如: [My Sect
- linux下批量查找替换工具,linux查找替换,FINDWORD TOO
- python logging 重复打印,pythonlogging,# -*- coding
- 自动生成类名头文件,自动生成类名头,该Python脚本程序
- 想着猜QZone的回答问题密码来着不大好用,想着qzone回答
- Tkinter 控件示例,tkinter控件示例,#_*_ coding:
- 生成字典,,程序名.py 1 -就会
- python通过xlrd模块读写Excel文件,pythonxlrd,一、安装xlrd模
- Tkinter 控件简单计算器示例,tkinter计算器示例,#_*_ cod
评论关闭