593 rql = 'Any X WHERE X eid in (%s)' % (','.join(eids)) |
593 rql = 'Any X WHERE X eid in (%s)' % (','.join(eids)) |
594 rset = self._cw.execute(rql) |
594 rset = self._cw.execute(rql) |
595 for entity in rset.entities(): |
595 for entity in rset.entities(): |
596 yield entity |
596 yield entity |
597 |
597 |
598 @property |
|
599 @cached |
|
600 def smtp(self): |
|
601 mailhost, port = self._cw.config['smtp-host'], self._cw.config['smtp-port'] |
|
602 try: |
|
603 return SMTP(mailhost, port) |
|
604 except Exception, ex: |
|
605 self.exception("can't connect to smtp server %s:%s (%s)", |
|
606 mailhost, port, ex) |
|
607 url = self._cw.build_url(__message=self._cw._('could not connect to the SMTP server')) |
|
608 raise Redirect(url) |
|
609 |
|
610 def sendmail(self, recipient, subject, body): |
598 def sendmail(self, recipient, subject, body): |
611 helo_addr = '%s <%s>' % (self._cw.config['sender-name'], |
|
612 self._cw.config['sender-addr']) |
|
613 msg = format_mail({'email' : self._cw.user.get_email(), |
599 msg = format_mail({'email' : self._cw.user.get_email(), |
614 'name' : self._cw.user.dc_title(),}, |
600 'name' : self._cw.user.dc_title(),}, |
615 [recipient], body, subject) |
601 [recipient], body, subject) |
616 self.smtp.sendmail(helo_addr, [recipient], msg.as_string()) |
602 if not self._cw.vreg.config.sendmails([(msg, [recipient])]): |
|
603 msg = self._cw._('could not connect to the SMTP server') |
|
604 url = self._cw.build_url(__message=msg) |
|
605 raise Redirect(url) |
617 |
606 |
618 def publish(self, rset=None): |
607 def publish(self, rset=None): |
619 # XXX this allows users with access to an cubicweb instance to use it as |
608 # XXX this allows users with access to an cubicweb instance to use it as |
620 # a mail relay |
609 # a mail relay |
621 body = self._cw.form['mailbody'] |
610 body = self._cw.form['mailbody'] |