python通过SMTPLIB发送邮件

#!/USR/BIN/PYTHON
import smtplib,string

class SendMail:
        def __init__(self,smtpServer,user="",passwd=""):
                self.smtpServer=smtpServer
                self.user=user
                self.passwd=passwd

        def sendmail(self,fromAddr,toAddr,subject,msg):
                server=smtplib.SMTP(self.smtpServer)

  if len(self.user)!=0 and len(self.passwd)!=0:
   server.login(self.user,self.passwd)
                body=string.join((
                        "FROM: %s" %fromAddr,
                        "TO: %s" %toAddr,
                        "Subject: %s" %subject,
                        "",
                        msg),"\r\n")

                server.sendmail(fromAddr,toAddr,body)
                server.quit()

if __name__ == "__main__":
 smDemo=SendMail("192.168.1.100","wuweixin","wwx’s passwd")
 smDemo.sendmail("wuweixin@pconline.com.cn","121957514@qq.com","SendMail Test","Just Test")

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Related posts:

  1. XML-RPC in Python简介

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu