cwconfig.py
changeset 9363 d773589b6d46
parent 9258 4e79f587c6ab
child 9669 283503f58400
equal deleted inserted replaced
9362:2f0129d17fa9 9363:d773589b6d46
  1175             create_dir(i18ndir)
  1175             create_dir(i18ndir)
  1176         sourcedirs = [join(path, 'i18n') for path in self.cubes_path()]
  1176         sourcedirs = [join(path, 'i18n') for path in self.cubes_path()]
  1177         sourcedirs.append(self.i18n_lib_dir())
  1177         sourcedirs.append(self.i18n_lib_dir())
  1178         return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs)
  1178         return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs)
  1179 
  1179 
  1180     def sendmails(self, msgs):
  1180     def sendmails(self, msgs, fromaddr=None):
  1181         """msgs: list of 2-uple (message object, recipients). Return False
  1181         """msgs: list of 2-uple (message object, recipients). Return False
  1182         if connection to the smtp server failed, else True.
  1182         if connection to the smtp server failed, else True.
  1183         """
  1183         """
  1184         server, port = self['smtp-host'], self['smtp-port']
  1184         server, port = self['smtp-host'], self['smtp-port']
       
  1185         if fromaddr is None:
       
  1186             fromaddr = '%s <%s>' % (self['sender-name'], self['sender-addr'])
  1185         SMTP_LOCK.acquire()
  1187         SMTP_LOCK.acquire()
  1186         try:
  1188         try:
  1187             try:
  1189             try:
  1188                 smtp = SMTP(server, port)
  1190                 smtp = SMTP(server, port)
  1189             except Exception as ex:
  1191             except Exception as ex:
  1190                 self.exception("can't connect to smtp server %s:%s (%s)",
  1192                 self.exception("can't connect to smtp server %s:%s (%s)",
  1191                                server, port, ex)
  1193                                server, port, ex)
  1192                 return False
  1194                 return False
  1193             heloaddr = '%s <%s>' % (self['sender-name'], self['sender-addr'])
       
  1194             for msg, recipients in msgs:
  1195             for msg, recipients in msgs:
  1195                 try:
  1196                 try:
  1196                     smtp.sendmail(heloaddr, recipients, msg.as_string())
  1197                     smtp.sendmail(fromaddr, recipients, msg.as_string())
  1197                 except Exception as ex:
  1198                 except Exception as ex:
  1198                     self.exception("error sending mail to %s (%s)",
  1199                     self.exception("error sending mail to %s (%s)",
  1199                                    recipients, ex)
  1200                                    recipients, ex)
  1200             smtp.close()
  1201             smtp.close()
  1201         finally:
  1202         finally: