Python写的smtp发送邮件脚本

#!/usr/bin/env python
#coding:gbk
#Author:小新他表哥
#Date:2013/08/26
import smtplib
from email.mime.text import MIMEText
############################################################
#发给谁
mailto_list=["741735870#qq.com","general_1989#sina.com"]
#Mail Server Info
mail_host="smtp.163.com"
mail_user="username"
mail_pass="邮箱密码"
mail_postfix="163.com"
#############################################################
def send_mail(to_list,subject,content):
'''
to_list:邮件接受者
subject:邮件主题
content:邮件内容
'''
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg.set_charset("gbk")
msg['Subject']=subject
msg['From']=me
msg['To']=";".join(to_list)
msg["Accept-Language"]="zh-CN"
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close
return True
exceptException,e:
print str(e)
return False
if __name__=='__main__':
if send_mail(mailto_list,"邮件测试","邮件测试内容,请删除"):
print "邮件发送成功"
else:
print "邮件发送失败"


你可能感兴趣的:(python)