Python发邮件代码
2018-07-20 来源:open-open
__author__ = 'administrator'
# encoding: utf-8
#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
mailto_list=['xx@qq.com','xx@126.com']
mail_host="smtp.126.com" #设置服务器
mail_user="xx@126.com" #用户名
mail_pass="123456" #口令
mail_postfix="126.com" #发件箱的后缀
def send_mail(to_list,sub,content):
me="hello"+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,_subtype='plain',_charset='utf-8')
msg['Subject'] = sub
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,"hello","hello world!我是中国"):
print "发送成功"
else:
print "发送失败"
标签: 服务器
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐