iro/anbieter/smtp.py
changeset 19 fcf8489f1c2f
parent 0 a3b6e531f0d2
child 20 0d7ffb9b2c7f
equal deleted inserted replaced
18:f0d31c70744d 19:fcf8489f1c2f
    23         self.section=section
    23         self.section=section
    24         self.bStart=False
    24         self.bStart=False
    25         self.bTLS=False
    25         self.bTLS=False
    26         self.bSSL=False
    26         self.bSSL=False
    27         self.max_recipients=1
    27         self.max_recipients=1
       
    28         
    28 
    29 
    29     def read_basic_config(self,config_filename=None):
    30     def read_basic_config(self,config_filename=None):
    30         """Read basic options from the config file"""
    31         """Read basic options from the config file"""
    31         if not (config_filename is None):
    32         if not (config_filename is None):
    32             self.config_filename=config_filename
    33             self.config_filename=config_filename
    48         try:
    49         try:
    49             self.bSSL=cp.getboolean(self.section, 'SSL')
    50             self.bSSL=cp.getboolean(self.section, 'SSL')
    50         except ValueError:
    51         except ValueError:
    51             self.bSSL=False
    52             self.bSSL=False
    52 
    53 
    53 
       
    54     def prepareSMTP(self):
    54     def prepareSMTP(self):
    55         if self.bSSL:
    55         if self.bSSL:
    56             self.smtp = smtplib.SMTP_SSL(self.host,self.port)
    56             self.smtp = smtplib.SMTP_SSL(self.host,self.port)
    57         else:
    57         else:
    58             self.smtp = smtplib.SMTP(self.host,self.port)
    58             self.smtp = smtplib.SMTP(self.host,self.port)
    68     def sendMail(self,mail,recipients):   
    68     def sendMail(self,mail,recipients):   
    69         if not self.bStart:
    69         if not self.bStart:
    70             self.prepareSMTP()
    70             self.prepareSMTP()
    71 
    71 
    72         mail.content['From']=self.send_from
    72         mail.content['From']=self.send_from
       
    73         
    73         while len(recipients) > 0:
    74         while len(recipients) > 0:
    74             tmp_recipients=recipients[:self.max_recipients]
    75             tmp_recipients=recipients[:self.max_recipients]
    75             print tmp_recipients
       
    76             self.smtp.sendmail(self.send_from,  tmp_recipients, mail.as_string())
    76             self.smtp.sendmail(self.send_from,  tmp_recipients, mail.as_string())
    77             self.updateStatus( arranged=tmp_recipients)
    77             self.updateStatus( arranged=tmp_recipients)
    78             recipients = recipients[self.max_recipients:]
    78             recipients = recipients[self.max_recipients:]
    79         
    79         
    80         self.smtp.shutdownSMTP()
    80         self.shutdownSMTP()
    81 
    81 
    82 
    82 
    83     def updateStatus(self, arranged=None, failed=None):
    83     def updateStatus(self, arranged=None, failed=None):
    84         """is a function that is called, if a new SMS/FAX was send
    84         """is a function that is called, if a new SMS/FAX was send
    85         -arranged is non None, if SMS/FAX was sended successfully
    85         -arranged is non None, if SMS/FAX was sended successfully