Browse Source

new module base_mail_bcc (#56)

* [ADD] new module base_mail_bcc

* [IMP] correct typos in README, change name of configuration parameter

* [REF] cleaned up code

* [IMP] base_mail_bcc: replicate exact API of super method

* [IMP] base_mail_bcc: add test code

* [REF] base_mail_bcc: code clean-up

* [IMP] base_mail_bcc: improve test coverage by triggering BCC-append case
pull/365/head
Thomas Rehn 7 years ago
committed by fkantelberg
parent
commit
d2be5110f6
  1. 58
      base_mail_bcc/README.rst
  2. 5
      base_mail_bcc/__init__.py
  3. 18
      base_mail_bcc/__openerp__.py
  4. 9
      base_mail_bcc/demo/mail_bcc_demo.xml
  5. 5
      base_mail_bcc/models/__init__.py
  6. 41
      base_mail_bcc/models/ir_mail_server.py
  7. 4
      base_mail_bcc/tests/__init__.py
  8. 20
      base_mail_bcc/tests/test_base_mail_bcc.py

58
base_mail_bcc/README.rst

@ -0,0 +1,58 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==============
BCC all emails
==============
This module extends the email mechanism to allow for sending a blind carbon copy (BCC)
of all outgoing emails to configurable e-mail addresses.
Configuration
=============
To configure this module, you need to:
* Go to Settings > Parameters > System Parameters
* Create a new entry with key `base_mail_bcc.bcc_to` and set the desired e-mail addresses for BCC as value. This value must be a comma-separated list of valid e-mail addresses.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/205/8.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Thomas Rehn <thomas.rehn@initos.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

5
base_mail_bcc/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

18
base_mail_bcc/__openerp__.py

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "BCC all emails",
"version": "8.0.1.0.0",
"depends": ["base"],
'author': 'initOS GmbH, Odoo Community Association (OCA)',
"category": "Tools",
'license': 'AGPL-3',
'data': [
],
'demo': ['demo/mail_bcc_demo.xml'],
'test': [
],
'installable': True,
'auto_install': False,
}

9
base_mail_bcc/demo/mail_bcc_demo.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="mail_bcc" model="ir.config_parameter">
<field name="key">base_mail_bcc.bcc_to</field>
<field name="value">root@example.com</field>
</record>
</data>
</openerp>

5
base_mail_bcc/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import ir_mail_server

41
base_mail_bcc/models/ir_mail_server.py

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# © 2014-2017 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from email.Utils import COMMASPACE
from openerp import models, api
class IrMailServer(models.Model):
_inherit = "ir.mail_server"
@api.model
def send_email(self, message, mail_server_id=None, smtp_server=None,
smtp_port=None, smtp_user=None, smtp_password=None,
smtp_encryption=None, smtp_debug=False):
""""Add global bcc email addresses"""
# These are added here in send_email instead of build_email
# because build_email is independent from the database and does not
# have a cursor as parameter.
ir_config_parameter = self.env["ir.config_parameter"]
config_email_bcc = ir_config_parameter.\
get_param("base_mail_bcc.bcc_to")
if config_email_bcc:
config_email_bcc = config_email_bcc.encode('ascii')
existing_bcc = []
if message['Bcc']:
existing_bcc.append(message['Bcc'])
del message['Bcc']
message['Bcc'] = COMMASPACE.join(
existing_bcc + config_email_bcc.split(',')
)
return super(IrMailServer, self).send_email(
message, mail_server_id=mail_server_id, smtp_server=smtp_server,
smtp_port=smtp_port, smtp_user=smtp_user,
smtp_password=smtp_password, smtp_encryption=smtp_encryption,
smtp_debug=smtp_debug
)

4
base_mail_bcc/tests/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# © 2017 initOS GmbH <https://www.initos.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_base_mail_bcc

20
base_mail_bcc/tests/test_base_mail_bcc.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2017 initOS GmbH <https://www.initos.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import mock
from openerp.tests.common import TransactionCase
class TestBaseMailBcc(TransactionCase):
def test_base_mail_bcc(self):
ir_mail_server = self.env['ir.mail_server']
message = ir_mail_server.build_email(
email_from='admin@example.com',
email_to='admin@example.com',
email_bcc='unused@example.com',
subject='An example E-Mail',
body='With an example body',
)
with mock.patch("smtplib.SMTP"):
ir_mail_server.send_email(message)
Loading…
Cancel
Save