iro/offer/smtp.py
branchdevel
changeset 169 aabc04843d25
parent 168 42b55855e3a6
child 171 5619596a0053
--- a/iro/offer/smtp.py	Wed Feb 15 14:43:37 2012 +0100
+++ b/iro/offer/smtp.py	Sat Feb 18 17:13:38 2012 +0100
@@ -21,7 +21,7 @@
 
 class SMTP(Provider):
     def __init__(self, name, config):
-        Provider.__init__(self,name,config,["std"],["mail"])
+        Provider.__init__(self,name,config,{"mail":[None]})
         
 
     def loadConfig(self):
@@ -50,40 +50,39 @@
                raise NeededOption(self.name, n) 
 
     def send(self,mail,recipient):   
+        if not self.testmode:
+            if self.bSSL:
+                smtp = smtplib.SMTP_SSL(self.host,self.port)
+            else:
+                smtp = smtplib.SMTP(self.host,self.port)
+            
+            if self.bTLS:
+                smtp.starttls()
+           
+            if not self.user == "":
+                smtp.login(self.user,self.password)
         try:
+            frm=self.send_from
+            
+            if mail.getFrom():
+                frm = mail.getFrom()
+            
+            tmpmail=copy.deepcopy(mail)
+            tmpmail.content['From'] = frm 
+            tmpmail.content['To']=recipient
             if not self.testmode:
-                if self.bSSL:
-                    smtp = smtplib.SMTP_SSL(self.host,self.port)
-                else:
-                    smtp = smtplib.SMTP(self.host,self.port)
-                
-                if self.bTLS:
-                    smtp.starttls()
-               
-                if not self.user == "":
-                    smtp.login(self.user,self.password)
-            try:
-                frm=self.send_from
-                
-                if mail.getFrom():
-                    frm = mail.getFrom()
-                
-                tmpmail=copy.deepcopy(mail)
-                tmpmail.content['From'] = frm 
-                tmpmail.content['To']=recipient
-                if not self.testmode:
-                    smtp.sendmail(frm,  recipient, tmpmail.as_string())
-                return Status(self, "std")
-            finally:
-                smtp.quit()
-        except Exception as e:
-            return Status(self,"std",e)
+                smtp.sendmail(frm,  recipient, tmpmail.as_string())
+            return Status(self, "std")
+        finally:
+            smtp.quit()
 
     def getSendFunc(self, typ, route):
-        if typ != "mail":
+        try:
+            if route not in self.typs[typ]:
+                raise NoRoute(route)
+        except KeyError:
             raise NoTyp(route)
-        elif  route != "std":
-            raise NoRoute(route)
+        
         return self.send
 
 providers["smtp"]=SMTP