[CLEAN] auth_signup, mail_mail: better management of exceptions when sending emails, delegated to mail_mail.
bzr revid: tde@openerp.com-20130604151508-7bd8gxhkr86fuybp
This commit is contained in:
parent
01c61499a3
commit
27839fead3
|
@ -270,14 +270,7 @@ class res_users(osv.Model):
|
|||
raise osv.except_osv(_("Cannot send email: user has no email address."), user.name)
|
||||
try:
|
||||
self.pool.get('email.template').send_mail(cr, uid, template.id, user.id, force_send=True, raise_exception=True, context=context)
|
||||
except AssertionError as e:
|
||||
# get the args of the original error, wrap into a value and throw a MailDeliveryException
|
||||
# that is an except_orm, with name and value as args
|
||||
value = '. '.join(e.args)
|
||||
if 'one valid recipient address should be specified' in e.args[0]:
|
||||
value += '. Please check that the user\'s email address is valid.'
|
||||
raise MailDeliveryException(_("Mail Delivery Failed"), value)
|
||||
except MailDeliveryException:
|
||||
except Exception:
|
||||
raise
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
|
|
|
@ -27,6 +27,7 @@ from urlparse import urljoin
|
|||
|
||||
from openerp import tools
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.addons.base.ir.ir_mail_server import MailDeliveryException
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
@ -304,8 +305,7 @@ class mail_mail(osv.Model):
|
|||
after sending each mail (meant only for scheduler processing);
|
||||
should never be True during normal transactions (default: False)
|
||||
:param bool raise_exception: whether to raise an exception if the
|
||||
email sending process has failed; auto_commit is taken into
|
||||
account.
|
||||
email sending process has failed
|
||||
:return: True
|
||||
"""
|
||||
ir_mail_server = self.pool.get('ir.mail_server')
|
||||
|
@ -351,12 +351,15 @@ class mail_mail(osv.Model):
|
|||
# see revid:odo@openerp.com-20120622152536-42b2s28lvdv3odyr in 6.1
|
||||
if mail_sent:
|
||||
self._postprocess_sent_message(cr, uid, mail, context=context)
|
||||
except Exception:
|
||||
if not raise_exception or auto_commit:
|
||||
_logger.exception('failed sending mail.mail %s', mail.id)
|
||||
mail.write({'state': 'exception'})
|
||||
cr.commit()
|
||||
except Exception as e:
|
||||
_logger.exception('failed sending mail.mail %s', mail.id)
|
||||
mail.write({'state': 'exception'})
|
||||
if raise_exception:
|
||||
if isinstance(e, AssertionError):
|
||||
# get the args of the original error, wrap into a value and throw a MailDeliveryException
|
||||
# that is an except_orm, with name and value as arguments
|
||||
value = '. '.join(e.args)
|
||||
raise MailDeliveryException(_("Mail Delivery Failed"), value)
|
||||
raise
|
||||
|
||||
if auto_commit == True:
|
||||
|
|
Loading…
Reference in New Issue