相关资料:
http://www.cnblogs.com/xiaowuyi
实例代码:
1 import smtplib 2 from email.mime.text import MIMEText 3 mailto_list=["zhu@163.com.cn"] 4 mail_host=r"exchange.163.com.cn" #设置服务器 5 mail_user="zhu" #用户名 6 mail_pass="123456789" #口令 7 mail_postfix="163.com.cn" #发件箱的后缀 8 9 def send_mail(to_list,sub,content): 10 me="<"+mail_user+"@"+mail_postfix+">" 11 msg = MIMEText(content,_subtype='plain',_charset='gb2312') 12 msg['Subject'] = sub 13 msg['From'] = me 14 msg['To'] = ";".join(to_list) 15 try: 16 server = smtplib.SMTP() 17 server.connect(mail_host) 18 server.login(mail_user,mail_pass) 19 server.sendmail(me, to_list, msg.as_string()) 20 server.close() 21 return True 22 except Exception, e: 23 print str(e) 24 return False 25 if __name__ == '__main__': 26 if send_mail(mailto_list,"hello","hello world!"): 27 print "发送成功" 28 else: 29 print "发送失败"