很早写的,本来觉得意义不大,还是放上来,以备丢了。python2.6下发送通过。
#!/bin/env python # -*- coding:utf-8 -*- # ------------------------------------------------------------------------------- # Filename: sendmail.py # Revision: 1.0 # Date: 2012-7-18 # Author: simonzhang # Email: simon-zzm@163.com # Web: www.simonzhang.net # ------------------------------------------------------------------------------- import smtplib from email.mime.text import MIMEText # mail_host = 'smtp.exmail.qq.com' mail_user = 'XXXXXXXX' mail_pwd = 'XXXXXXXXX' def mail_send(content, mailto, get_sub): msg = MIMEText(content.encode('utf8'), _subtype='html', _charset='utf8') msg['From'] = mail_user msg['Subject'] = u'%s' % get_sub msg['To'] = mailto try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pwd) s.sendmail(mail_user,[mailto],msg.as_string()) s.close() except Exception ,e: print e
nice post,thanks for share.
thanks, nice post.