python用smtplib来发邮件十分简单。再说,在google也算是一搜一大把的例子,这里只是我的记录:)

 

 

--------------

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import smtplib
class MyMail(object):
    def __init__(self,host='localhost'):
        self.svr = smtplib.SMTP(host)
        self.svr.set_debuglevel(0)
    def send(self,fro,to,msg):
        self.svr.sendmail(fro,to,msg)
        self.svr.quit()if __name__ == '__main__':
    amail    = MyMail('192.168.xx.xx')
    fromaddr = 'xx@xx.com'    toaddr   = fromaddr + ',' + fromaddr
    import time
    dtime    = time.strftime("%Y-%m-%d %H:%I:%S",time.localtime())
    msg      = """From: %s
                  Date: %s
                  To: %s
                  Reply-To: <xx@xx.com>
                  Subject:  This is “测试” Mail!                  参考:http://www.google.com  
                  """  % (fromaddr, dtime,toaddr)
    amail.send(fromaddr,toaddr,msg)