You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # License AGPL-3: Antiun Ingenieria S.L. - Antonio Espinosa
  3. # See README.rst file on addon root folder for more details
  4. import json
  5. import threading
  6. from openerp import models, api
  7. class MailMail(models.Model):
  8. _inherit = 'mail.mail'
  9. def _mandrill_headers_add(self):
  10. for mail in self.sudo():
  11. headers = {}
  12. if mail.headers:
  13. try:
  14. headers.update(eval(mail.headers))
  15. except Exception:
  16. pass
  17. metadata = {
  18. 'odoo_db': getattr(threading.currentThread(), 'dbname', None),
  19. 'odoo_model': mail.model,
  20. 'odoo_id': mail.res_id,
  21. }
  22. headers['X-MC-Metadata'] = json.dumps(metadata)
  23. mail.headers = repr(headers)
  24. return True
  25. @api.multi
  26. def send(self, auto_commit=False, raise_exception=False):
  27. self._mandrill_headers_add()
  28. super(MailMail, self).send(
  29. auto_commit=auto_commit,
  30. raise_exception=raise_exception)
  31. return True