python邮件发送
2016-04-22 15:14
495 查看
#coding: utf-8
'''
发送txt文本邮件
'''
import smtplib
from email.mime.text import MIMEText
mailto_list=['****@163.com']
mail_host="smtp.163.com" #设置服务器
mail_user="****@163.com" #用户名
mail_pass="*****" #口令
title = "Application Received from %s" % mail_user
def send_mail(to_list,title,content):
me= mail_user
msg = MIMEText(content,_subtype='plain',_charset='utf-8')
msg['Subject'] = title
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user,mail_pass)
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(mailto_list,title,"hello world!"):
print "发送成功"
else:
print "发送失败"
'''
发送txt文本邮件
'''
import smtplib
from email.mime.text import MIMEText
mailto_list=['****@163.com']
mail_host="smtp.163.com" #设置服务器
mail_user="****@163.com" #用户名
mail_pass="*****" #口令
title = "Application Received from %s" % mail_user
def send_mail(to_list,title,content):
me= mail_user
msg = MIMEText(content,_subtype='plain',_charset='utf-8')
msg['Subject'] = title
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user,mail_pass)
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(mailto_list,title,"hello world!"):
print "发送成功"
else:
print "发送失败"
相关文章推荐
- python中requests使用代理proxies
- Windos 下python2.7安装 pymssql 解决方案
- python for循环
- Python 素数判断;以及默尼森数
- python 如何实现反转倒序
- python中的 字符串与list的互相转换 (join函数的使用)
- python版本
- Python之SQLAlchemy
- Python学习-机器学习实战-ch05 Logistic回归
- python while循环
- 理解Python的with语句
- python的exec, execfile,compile, eval
- Python3 urllib.parse 常用函数示例
- Python学习一(面向对象和函数式编程)
- Python yield 使用浅析
- python脚本按表备份MySQL数据库
- python 读取文件以及对文件的json字符串的操作
- Python爬虫----爬虫入门(4)---urllib2 模拟登陆
- Python的set集合浅析
- Python编程技巧(一)