iro/anbieter/smtp.py
changeset 20 0d7ffb9b2c7f
parent 19 fcf8489f1c2f
child 23 0180b538ed74
equal deleted inserted replaced
19:fcf8489f1c2f 20:0d7ffb9b2c7f
    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 
       
    19 
    18 
    20 class SMTP():
    19 class SMTP():
    21     def __init__(self,config_filename=None,section="smtp"):
    20     def __init__(self,config_filename=None,section="smtp"):
    22         self.config_filename=config_filename
    21         self.config_filename=config_filename
    23         self.section=section
    22         self.section=section
    64             self.smtp.login(self.user,self.pw)
    63             self.smtp.login(self.user,self.pw)
    65         
    64         
    66         self.bStart=True
    65         self.bStart=True
    67 
    66 
    68     def sendMail(self,mail,recipients):   
    67     def sendMail(self,mail,recipients):   
       
    68         import logging
       
    69         logging.debug('SMTP.sendMail(%s,%s)'%(mail,  str(recipients)))
    69         if not self.bStart:
    70         if not self.bStart:
    70             self.prepareSMTP()
    71             self.prepareSMTP()
    71 
    72 
    72         mail.content['From']=self.send_from
    73         mail.content['From']=self.send_from
    73         
    74         
    74         while len(recipients) > 0:
    75         while len(recipients) > 0:
    75             tmp_recipients=recipients[:self.max_recipients]
    76             tmp_recipients=recipients[:self.max_recipients]
       
    77             mail.content['To']=", ".join(tmp_recipients)
       
    78             logging.debug('self.smtp.sendmail(%s,%s,%s)'%(self.send_from,  str(tmp_recipients), mail.as_string()))
    76             self.smtp.sendmail(self.send_from,  tmp_recipients, mail.as_string())
    79             self.smtp.sendmail(self.send_from,  tmp_recipients, mail.as_string())
    77             self.updateStatus( arranged=tmp_recipients)
    80             self.updateStatus( arranged=tmp_recipients)
    78             recipients = recipients[self.max_recipients:]
    81             recipients = recipients[self.max_recipients:]
    79         
    82         
    80         self.shutdownSMTP()
    83         self.shutdownSMTP()