python使用qq服务器发送邮件
来源:互联网 发布:办公软件应用教程 编辑:程序博客网 时间:2024/05/29 19:48
python使用qq服务器发送邮件
直接上代码:
#!/usr/bin/python2.7#-*- coding: UTF-8 -*-# sendmail.py## init created: 2016-04-21# last updated: 2016-04-21########################################################################import smtplibfrom email.mime.text import MIMETextimport tracebackclass SmtpSendMail: def __init__(self, config): try: # 设置发件服务器地址, 如: "smtp.qq.com" self.host = config["host"] # 设置发件服务器端口号. 有SSL(465)和非SSL(25)两种形式 self.port = config["port"] # 设置发件邮箱, 一定要自己注册的邮箱, 如: "cheungmine@qq.com" self.sender = config["sender"] # 设置发件邮箱的密码, 登陆会用到 self.password = config["password"] # 设置超时秒 self.timeout = config["timeout"] # SSL if not config.get("SSL"): self.SSL = False else: self.SSL = True # session if self.SSL: session = smtplib.SMTP_SSL(self.host, self.port, self.timeout) else: session = smtplib.SMTP(self.host, self.port, self.timeout) # 登陆邮箱 session.login(self.sender, self.password) self.session = session except Exception, e: traceback.print_exc() pass def sendmail(self, mailto): result = False try: # 设置正文为符合邮件格式的HTML内容 msg = MIMEText(mailto["body"], 'html') # 设置邮件标题 msg['subject'] = mailto["title"] # 设置发送人 msg['from'] = self.sender # 设置邮件接收人 msg['to'] = mailto["receiver"] # 发送邮件 self.session.sendmail(self.sender, mailto["receiver"], msg.as_string()) result = True except Exception, e: traceback.print_exc() finally: return result pass# testmailfrom = { "host": "smtp.qq.com", "port": 465, "sender": "cheungmine@qq.com", "password": "xxxxx", "timeout": 30, "SSL": True}mailto = { "receiver": "350137278@qq.com", "title": "This is a test mail", "body": "<h1>Hi</h1><p>test mail from cheungmine</p>"}smtp = SmtpSendMail(mailfrom)print smtp.sendmail(mailto)
0 0
- python使用qq服务器发送邮件
- python发送QQ邮件
- python发送qq邮件
- Python发送QQ邮件
- Python 发送QQ邮件
- Python 通过连接qq邮箱服务器发送邮件
- 记common-email发送邮件,使用qq邮箱服务器
- A002:Python发送qq邮件
- Python SMTP发送QQ邮件
- PYTHON smtp 发送qq邮件
- Python 发送QQ邮件封装
- JAVA 使用QQ发送邮件
- 使用javamail发送qq邮件
- 使用qq邮箱发送邮件
- java使用qq发送邮件
- 使用PYTHON发送邮件
- 使用Python发送邮件
- 使用python发送邮件
- python 实验5 字符串练习(一)
- 软件名称: 会声会影x8注册机 v3.9 绿色版
- alter table move和 shrink space
- obs classic 代码阅读一
- vs2010中 包含目录 和 常规-》附加包含目录 的区别
- python使用qq服务器发送邮件
- Android天气预报程序(八)
- 【架构】关于RabbitMQ
- Microsoft.ACE.OLEDB.12.0
- c++11 auto
- 点击导航按钮后进入百度地图app,如果手机没有安装的话,就跳转到AppStore
- JS拦截方法
- maven的pom报plugins缺失的解决方法
- Centos6.5安装gcc及g++