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.

41 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2014-2017 Thomas Rehn (initOS GmbH)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from email.Utils import COMMASPACE
  5. from openerp import models, api
  6. class IrMailServer(models.Model):
  7. _inherit = "ir.mail_server"
  8. @api.model
  9. def send_email(self, message, mail_server_id=None, smtp_server=None,
  10. smtp_port=None, smtp_user=None, smtp_password=None,
  11. smtp_encryption=None, smtp_debug=False):
  12. """"Add global bcc email addresses"""
  13. # These are added here in send_email instead of build_email
  14. # because build_email is independent from the database and does not
  15. # have a cursor as parameter.
  16. ir_config_parameter = self.env["ir.config_parameter"]
  17. config_email_bcc = ir_config_parameter.\
  18. get_param("base_mail_bcc.bcc_to")
  19. if config_email_bcc:
  20. config_email_bcc = config_email_bcc.encode('ascii')
  21. existing_bcc = []
  22. if message['Bcc']:
  23. existing_bcc.append(message['Bcc'])
  24. del message['Bcc']
  25. message['Bcc'] = COMMASPACE.join(
  26. existing_bcc + config_email_bcc.split(',')
  27. )
  28. return super(IrMailServer, self).send_email(
  29. message, mail_server_id=mail_server_id, smtp_server=smtp_server,
  30. smtp_port=smtp_port, smtp_user=smtp_user,
  31. smtp_password=smtp_password, smtp_encryption=smtp_encryption,
  32. smtp_debug=smtp_debug
  33. )