iro/offer/smtp.py
branchdevel
changeset 171 5619596a0053
parent 169 aabc04843d25
child 180 55ab949cf0f8
equal deleted inserted replaced
170:2a16943f1d05 171:5619596a0053
    13 
    13 
    14 import smtplib
    14 import smtplib
    15 import copy
    15 import copy
    16 
    16 
    17 from ..model.status import Status
    17 from ..model.status import Status
    18 from ..error import UnknownOption, NeededOption, NoRoute, NoTyp
    18 from ..error import UnknownOption, NeededOption
    19 from ..offer import providers
    19 from ..offer import providers
    20 from .provider import Provider
    20 from .provider import Provider
    21 
    21 
    22 class SMTP(Provider):
    22 class SMTP(Provider):
    23     def __init__(self, name, config):
    23     def __init__(self, name, config):
    70             tmpmail=copy.deepcopy(mail)
    70             tmpmail=copy.deepcopy(mail)
    71             tmpmail.content['From'] = frm 
    71             tmpmail.content['From'] = frm 
    72             tmpmail.content['To']=recipient
    72             tmpmail.content['To']=recipient
    73             if not self.testmode:
    73             if not self.testmode:
    74                 smtp.sendmail(frm,  recipient, tmpmail.as_string())
    74                 smtp.sendmail(frm,  recipient, tmpmail.as_string())
    75             return Status(self, "std")
    75             return Status(self, None)
    76         finally:
    76         finally:
    77             smtp.quit()
    77             smtp.quit()
    78 
    78 
    79     def getSendFunc(self, typ, route):
    79     def getSendFunc(self, typ, route):
    80         try:
    80         Provider.getSendFunc(self, typ, route)
    81             if route not in self.typs[typ]:
       
    82                 raise NoRoute(route)
       
    83         except KeyError:
       
    84             raise NoTyp(route)
       
    85         
       
    86         return self.send
    81         return self.send
    87 
    82 
    88 providers["smtp"]=SMTP
    83 providers["smtp"]=SMTP
    89 
    84