diff --git a/mail_send_copy/README.rst b/mail_send_copy/README.rst new file mode 100644 index 0000000000..780c6b3cf2 --- /dev/null +++ b/mail_send_copy/README.rst @@ -0,0 +1,99 @@ +====================== +Mail - Send Email Copy +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:60a0e4b95442e035817471582351372a89c0c863900a2fb572386a6d3fee9ea9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/18.0/mail_send_copy + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_send_copy + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of Mail Module adding sender in +BBC field to receive a copy of each mail sent by Odoo. + +.. warning:: + + Sender can be different from the current user according email + template in use. + +Use Case +-------- + +This feature can be usefull for users: + +- to be sure the mail was sent because Odoo send mail depending of some + partner parameters +- to have the whole conversation if the partner writes an answer and if + mailbox manages thread by object +- to be sure smtp server works + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +- Add the possibility to select if the mail is sent in "Cc" or in "Bcc" + mode. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* GRAP + +Contributors +------------ + +- Sylvain LE GAL (https://www.twitter.com/legalsylvain) + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_send_copy/__init__.py b/mail_send_copy/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mail_send_copy/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_send_copy/__manifest__.py b/mail_send_copy/__manifest__.py new file mode 100644 index 0000000000..b82de20b07 --- /dev/null +++ b/mail_send_copy/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright (C) 2014 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Mail - Send Email Copy", + "summary": "Send to you a copy of each mail sent by Odoo", + "version": "18.0.1.0.1", + "category": "Social Network", + "author": "GRAP," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "license": "AGPL-3", + "depends": ["mail"], + "installable": True, +} diff --git a/mail_send_copy/i18n/fr.po b/mail_send_copy/i18n/fr.po new file mode 100644 index 0000000000..39f7d130d7 --- /dev/null +++ b/mail_send_copy/i18n/fr.po @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_send_copy +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-11-13 10:48+0000\n" +"PO-Revision-Date: 2019-11-13 10:48+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_send_copy +#: model:ir.model,name:mail_send_copy.model_ir_mail_server +msgid "Mail Server" +msgstr "Serveur d'email" + +#~ msgid "Users" +#~ msgstr "Utilisateurs" diff --git a/mail_send_copy/i18n/mail_send_copy.pot b/mail_send_copy/i18n/mail_send_copy.pot new file mode 100644 index 0000000000..aa794630fb --- /dev/null +++ b/mail_send_copy/i18n/mail_send_copy.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_send_copy +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_send_copy +#: model:ir.model,name:mail_send_copy.model_ir_mail_server +msgid "Mail Server" +msgstr "" diff --git a/mail_send_copy/models/__init__.py b/mail_send_copy/models/__init__.py new file mode 100644 index 0000000000..abbcb50bd0 --- /dev/null +++ b/mail_send_copy/models/__init__.py @@ -0,0 +1 @@ +from . import ir_mail_server diff --git a/mail_send_copy/models/ir_mail_server.py b/mail_send_copy/models/ir_mail_server.py new file mode 100644 index 0000000000..358e104567 --- /dev/null +++ b/mail_send_copy/models/ir_mail_server.py @@ -0,0 +1,36 @@ +# Copyright (C) 2014 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging +from email.utils import COMMASPACE + +from odoo import api, models + +_logger = logging.getLogger(__name__) + + +class IrMailServer(models.Model): + _inherit = "ir.mail_server" + + @api.model + def send_email(self, message, *args, **kwargs): + do_not_send_copy = self.env.context.get("do_not_send_copy", False) + if not do_not_send_copy: + # Get existing Bcc recipients (if any) + bcc = message.get("Bcc", "") + from_addr = message.get("From", "") + + # Combine existing Bcc with From address + if bcc: + all_bcc = COMMASPACE.join([bcc, from_addr]) + else: + all_bcc = from_addr + + # Set the combined Bcc + if "Bcc" in message: + message.replace_header("Bcc", all_bcc) + else: + message.add_header("Bcc", all_bcc) + + return super().send_email(message, *args, **kwargs) diff --git a/mail_send_copy/pyproject.toml b/mail_send_copy/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/mail_send_copy/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_send_copy/readme/CONTRIBUTORS.md b/mail_send_copy/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..4a6b63400c --- /dev/null +++ b/mail_send_copy/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Sylvain LE GAL () diff --git a/mail_send_copy/readme/DESCRIPTION.md b/mail_send_copy/readme/DESCRIPTION.md new file mode 100644 index 0000000000..69a7c581cc --- /dev/null +++ b/mail_send_copy/readme/DESCRIPTION.md @@ -0,0 +1,16 @@ +This module extends the functionality of Mail Module adding sender in +BBC field to receive a copy of each mail sent by Odoo. + +> [!WARNING] +> Sender can be different from the current user according email template +> in use. + +## Use Case + +This feature can be usefull for users: + +- to be sure the mail was sent because Odoo send mail depending of some + partner parameters +- to have the whole conversation if the partner writes an answer and if + mailbox manages thread by object +- to be sure smtp server works diff --git a/mail_send_copy/readme/ROADMAP.md b/mail_send_copy/readme/ROADMAP.md new file mode 100644 index 0000000000..f348c55eca --- /dev/null +++ b/mail_send_copy/readme/ROADMAP.md @@ -0,0 +1,2 @@ +- Add the possibility to select if the mail is sent in "Cc" or in "Bcc" + mode. diff --git a/mail_send_copy/static/description/icon.png b/mail_send_copy/static/description/icon.png new file mode 100644 index 0000000000..9414ac9fdf Binary files /dev/null and b/mail_send_copy/static/description/icon.png differ diff --git a/mail_send_copy/static/description/index.html b/mail_send_copy/static/description/index.html new file mode 100644 index 0000000000..12a8562b59 --- /dev/null +++ b/mail_send_copy/static/description/index.html @@ -0,0 +1,443 @@ + + + + + +Mail - Send Email Copy + + + +
+

Mail - Send Email Copy

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

This module extends the functionality of Mail Module adding sender in +BBC field to receive a copy of each mail sent by Odoo.

+
+

Warning

+

Sender can be different from the current user according email +template in use.

+
+
+

Use Case

+

This feature can be usefull for users:

+
    +
  • to be sure the mail was sent because Odoo send mail depending of some +partner parameters
  • +
  • to have the whole conversation if the partner writes an answer and if +mailbox manages thread by object
  • +
  • to be sure smtp server works
  • +
+

Table of contents

+ +
+

Known issues / Roadmap

+
    +
  • Add the possibility to select if the mail is sent in “Cc” or in “Bcc” +mode.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+ +
+
+

Authors

+
    +
  • GRAP
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+ + diff --git a/mail_send_copy/tests/__init__.py b/mail_send_copy/tests/__init__.py new file mode 100644 index 0000000000..9780ffc8ba --- /dev/null +++ b/mail_send_copy/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_send_copy diff --git a/mail_send_copy/tests/test_mail_send_copy.py b/mail_send_copy/tests/test_mail_send_copy.py new file mode 100644 index 0000000000..99a8d63041 --- /dev/null +++ b/mail_send_copy/tests/test_mail_send_copy.py @@ -0,0 +1,114 @@ +# Copyright from 2024: Alwinen GmbH (https://www.alwinen.de) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +# TODO: find a way to test sending email with existing BCC + +from unittest.mock import patch + +from odoo import Command +from odoo.tests import tagged + +from odoo.addons.mail.tests.test_mail_composer import TestMailComposer + + +class TestMailSendCopy(TestMailComposer): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context={"testing": True}) + + # Create test partner + cls.partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + "email": "test@example.com", + } + ) + + def test_send_email_with_copy(self): + """Test that sender is added to BCC when sending email""" + composer = self.env["mail.compose.message"].create( + { + "model": "res.partner", + "res_ids": [self.partner.id], + "partner_ids": [Command.set(self.partner.ids)], + "subject": "Test Subject No Copy", + "body": "

Test Body

", + "email_from": "sender@example.com", + "composition_mode": "comment", + } + ) + # Mock the send_email method + with patch( + "odoo.addons.base.models.ir_mail_server.IrMailServer.send_email" + ) as mock_send_email: + composer._action_send_mail() + # Verify that send_email was called + self.assertTrue(mock_send_email.called) + # Get the arguments passed to send_email + call_args = mock_send_email.call_args[0] + # The message is the first argument + message = call_args[0] + # Check BCC in the email message + self.assertIn("sender@example.com", message["Bcc"]) + + def test_send_email_without_copy(self): + """Test that sender is not added to BCC when do_not_send_copy is True""" + composer = ( + self.env["mail.compose.message"] + .with_context(do_not_send_copy=True) + .create( + { + "model": "res.partner", + "res_ids": [self.partner.id], + "partner_ids": [Command.set(self.partner.ids)], + "subject": "Test Subject No Copy", + "body": "

Test Body

", + "email_from": "sender@example.com", + "composition_mode": "comment", + } + ) + ) + + with patch( + "odoo.addons.base.models.ir_mail_server.IrMailServer.send_email" + ) as mock_send_email: + composer._action_send_mail() + self.assertTrue(mock_send_email.called) + message = mock_send_email.call_args[0][0] + self.assertNotIn("Bcc", message) + + +# Code contributed by @trisdoan +@tagged("post_install", "-at_install") +class TestMailSendWithBcc(TestMailSendCopy): + def test_send_email_with_existing_bcc(self): + if not self.env["ir.module.module"].search( + [("name", "=", "mail_composer_cc_bcc"), ("state", "=", "installed")] + ): + self.skipTest("mail_composer_cc_bcc module is required for this test") + + partner_bcc = self.env.ref("base.res_partner_main2") + composer = self.env["mail.compose.message"].create( + { + "model": "res.partner", + "res_ids": [self.partner.id], + "partner_ids": [Command.set(self.partner.ids)], + "subject": "Test Subject No Copy", + "body": "

Test Body

", + "email_from": "sender@example.com", + "composition_mode": "comment", + } + ) + composer.partner_bcc_ids = partner_bcc + + with patch( + "odoo.addons.base.models.ir_mail_server.IrMailServer.send_email" + ) as mock_send_email: + composer._action_send_mail() + # Verify that send_email was called + self.assertTrue(mock_send_email.called) + call_args = mock_send_email.call_args[0] + message = call_args[0] + # Check existing BCC in the email message + self.assertIn("dwayne.newman28@example.com", message["Bcc"])