iro/anbieter/smtp.py
changeset 23 0180b538ed74
parent 20 0d7ffb9b2c7f
child 37 6e5bd561ddd0
equal deleted inserted replaced
22:8b363361ba55 23:0180b538ed74
    13 
    13 
    14 class anbieter:
    14 class anbieter:
    15     default_conf = ''    # override this
    15     default_conf = ''    # override this
    16 import smtplib
    16 import smtplib
    17 import ConfigParser
    17 import ConfigParser
       
    18 import logging
       
    19 logger=logging.getLogger("SMTP")
    18 
    20 
    19 class SMTP():
    21 class SMTP():
    20     def __init__(self,config_filename=None,section="smtp"):
    22     def __init__(self,config_filename=None,section="smtp"):
    21         self.config_filename=config_filename
    23         self.config_filename=config_filename
    22         self.section=section
    24         self.section=section
    63             self.smtp.login(self.user,self.pw)
    65             self.smtp.login(self.user,self.pw)
    64         
    66         
    65         self.bStart=True
    67         self.bStart=True
    66 
    68 
    67     def sendMail(self,mail,recipients):   
    69     def sendMail(self,mail,recipients):   
    68         import logging
    70         logger.debug('SMTP.sendMail(%s,%s)'%(mail,  str(recipients)))
    69         logging.debug('SMTP.sendMail(%s,%s)'%(mail,  str(recipients)))
       
    70         if not self.bStart:
    71         if not self.bStart:
    71             self.prepareSMTP()
    72             self.prepareSMTP()
    72 
    73 
    73         mail.content['From']=self.send_from
    74         mail.content['From']=self.send_from
    74         
    75         
    75         while len(recipients) > 0:
    76         while len(recipients) > 0:
    76             tmp_recipients=recipients[:self.max_recipients]
    77             tmp_recipients=recipients[:self.max_recipients]
    77             mail.content['To']=", ".join(tmp_recipients)
    78             mail.content['To']=", ".join(tmp_recipients)
    78             logging.debug('self.smtp.sendmail(%s,%s,%s)'%(self.send_from,  str(tmp_recipients), mail.as_string()))
    79             logger.debug('self.smtp.sendmail(%s,%s,%s)'%(self.send_from,  str(tmp_recipients), mail.as_string()))
    79             self.smtp.sendmail(self.send_from,  tmp_recipients, mail.as_string())
    80             self.smtp.sendmail(self.send_from,  tmp_recipients, mail.as_string())
    80             self.updateStatus( arranged=tmp_recipients)
    81             self.updateStatus( arranged=tmp_recipients)
    81             recipients = recipients[self.max_recipients:]
    82             recipients = recipients[self.max_recipients:]
    82         
    83         
    83         self.shutdownSMTP()
    84         self.shutdownSMTP()