Skip to content

Commit e04e4c5

Browse files
committed
[ADD] mail_force_email_notification
1 parent d4b5f80 commit e04e4c5

15 files changed

Lines changed: 758 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
=============================
2+
Mail Force Email Notification
3+
=============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:abe986a2c488a0007237bf74d451abb23f15ac28889b9a30d3b40de0eab937aa
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github
20+
:target: https://github.com/OCA/mail/tree/18.0/mail_force_email_notification
21+
:alt: OCA/mail
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_force_email_notification
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module extends the functionality of Odoo's mail notification system
32+
to allow forcing email notifications through context keys. By default,
33+
Odoo sends internal notifications to connected users and email
34+
notifications to external partners or disconnected users.
35+
36+
With this module, you can override this behavior by setting the
37+
``force_notification_by_email`` context key, ensuring specific
38+
notifications are always sent by email regardless of the user's
39+
connection status or notification preferences. This is particularly
40+
useful when you need to maintain an email trail for certain
41+
communications or ensure critical notifications are delivered via email.
42+
43+
**Table of contents**
44+
45+
.. contents::
46+
:local:
47+
48+
Usage
49+
=====
50+
51+
To use this module, you need to:
52+
53+
1. For developers implementing the feature:
54+
55+
- Add the context key ``force_notification_by_email=True`` when
56+
sending messages through the mail thread
57+
58+
.. code:: python
59+
60+
self.env['mail.thread'].with_context(
61+
force_notification_by_email=True
62+
).message_post(
63+
body="Your message",
64+
partner_ids=[partner.id],
65+
)
66+
67+
2. For end users:
68+
69+
- No specific configuration is needed
70+
- When developers have implemented the feature in specific actions:
71+
72+
- Messages will be sent by email regardless of your notification
73+
preferences
74+
- You will receive email notifications even if you are connected to
75+
Odoo
76+
- Your notification preferences in your user settings won't affect
77+
these specific notifications
78+
79+
**Example Use Cases:**
80+
81+
- Critical notifications that need email documentation
82+
- Automated workflows where email trail is required
83+
- Compliance requirements where email proof of communication is
84+
necessary
85+
86+
**Note:** This module only affects notifications where the context key
87+
has been specifically implemented. All other notifications will follow
88+
standard Odoo behavior.
89+
90+
Bug Tracker
91+
===========
92+
93+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_.
94+
In case of trouble, please check there if your issue has already been reported.
95+
If you spotted it first, help us to smash it by providing a detailed and welcomed
96+
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_force_email_notification%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
97+
98+
Do not contact contributors directly about support or help with technical issues.
99+
100+
Credits
101+
=======
102+
103+
Authors
104+
-------
105+
106+
* Camptocamp
107+
108+
Contributors
109+
------------
110+
111+
- `Camptocamp <https://www.camptocamp.com>`__
112+
113+
- Rafael Lima <rafael.lima@camptocamp.com>
114+
115+
Other credits
116+
-------------
117+
118+
The development of this module has been financially supported by
119+
Camptocamp.
120+
121+
Maintainers
122+
-----------
123+
124+
This module is maintained by the OCA.
125+
126+
.. image:: https://odoo-community.org/logo.png
127+
:alt: Odoo Community Association
128+
:target: https://odoo-community.org
129+
130+
OCA, or the Odoo Community Association, is a nonprofit organization whose
131+
mission is to support the collaborative development of Odoo features and
132+
promote its widespread use.
133+
134+
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_force_email_notification>`_ project on GitHub.
135+
136+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2025 Camptocamp (http://www.camptocamp.com).
2+
# @author Rafael Lima <rafael.lima@camptocamp.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Mail Force Email Notification",
7+
"summary": "Context key to define notifications to be sent by email"
8+
"defined by force_notification_by_email context key",
9+
"version": "18.0.1.0.0",
10+
"author": "Camptocamp, Odoo Community Association (OCA)",
11+
"license": "AGPL-3",
12+
"category": "Hidden",
13+
"depends": ["mail"],
14+
"website": "https://github.com/OCA/mail",
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import mail_thread
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2022 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from odoo import models
5+
6+
7+
class MailThread(models.AbstractModel):
8+
_inherit = "mail.thread"
9+
10+
def _notify_get_recipients(self, message, msg_vals, **kwargs):
11+
recipients = super()._notify_get_recipients(message, msg_vals, **kwargs)
12+
# The context key `force_notification_by_email` allows to
13+
# push notifications through email even if the user has his preferences
14+
# configured to use Odoo.
15+
if self.env.context.get("force_notification_by_email"):
16+
for partner in recipients:
17+
partner["notif"] = "email"
18+
return recipients
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [Camptocamp](https://www.camptocamp.com)
2+
3+
> - Rafael Lima \<rafael.lima@camptocamp.com\>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The development of this module has been financially supported by Camptocamp.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module extends the functionality of Odoo's mail notification system to allow forcing email notifications through context keys. By default, Odoo sends internal notifications to connected users and email notifications to external partners or disconnected users.
2+
3+
With this module, you can override this behavior by setting the `force_notification_by_email` context key, ensuring specific notifications are always sent by email regardless of the user's connection status or notification preferences. This is particularly useful when you need to maintain an email trail for certain communications or ensure critical notifications are delivered via email.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
To use this module, you need to:
2+
3+
1. For developers implementing the feature:
4+
- Add the context key `force_notification_by_email=True` when sending messages through the mail thread
5+
```python
6+
self.env['mail.thread'].with_context(
7+
force_notification_by_email=True
8+
).message_post(
9+
body="Your message",
10+
partner_ids=[partner.id],
11+
)
12+
```
13+
14+
2. For end users:
15+
- No specific configuration is needed
16+
- When developers have implemented the feature in specific actions:
17+
- Messages will be sent by email regardless of your notification preferences
18+
- You will receive email notifications even if you are connected to Odoo
19+
- Your notification preferences in your user settings won't affect these specific notifications
20+
21+
**Example Use Cases:**
22+
23+
- Critical notifications that need email documentation
24+
- Automated workflows where email trail is required
25+
- Compliance requirements where email proof of communication is necessary
26+
27+
**Note:** This module only affects notifications where the context key has been specifically implemented. All other notifications will follow standard Odoo behavior.

0 commit comments

Comments
 (0)