- 论坛徽章:
- 0
|
#!/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("
[email=wuweixin@pconline.com.cn","121957514@qq.com","SendMail]wuweixin@pconline.com.cn","121957514@qq.com","SendMail[/email]
Test","Just Test")
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/104219/showart_2069522.html |
|