http://blog.csdn.net/lucahan/article/details/52070944
#! /usr/bin/env python #-*-coding:utf-8-*-import smtplib from email.mime.text import mimetext mailto_list=[' [EMAIL&N Bsp;protected] #收件人 (list) mail_host= "smtp.163.com" #使用的邮箱的smtp服务器地址, here is the SMTP address of 163 mail_user= "XXX" #用户名 mail_pass= "XXX" #密码 mail_postfix= "163.com" #邮箱的后缀, NetEase is 163.com def send_mail (to_list,sub,content): me= "Hello" + "<" +mail_user+ "@" +mail_postfix+ ">" msg = Mimetext (content,_subtype= ' plain ') msg[' Subject '] = Sub msg[' from ' = Me msg[' to '] = ";". Join (to_list) #将收件人列表以 '; ' Separates 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 for I in rangE (1): #发送1封, the list above is a few people, this will fill in a few if Send_mail (mailto_list, "phone", "phone is xxx"): #邮件主题和邮件内容 #这是最好写点中文, if you write casually, may be netease as spam message back print "done!" Else:print "failed!"
Python Send mail