Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
01e68ee
OCA Transbot updated translations from Transifex
antespi Sep 19, 2016
298bbdb
[ADD] mail_tracking_mailgun
antespi Jul 15, 2016
6581fa4
[8.0][IMP][mail_tracking] Speed installation time and discard concurr…
antespi Sep 9, 2016
57ea589
[MIG] mail_tracking_mailgun
antespi Sep 13, 2016
7cc97eb
[MIG] Make modules uninstallable
pedrobaeza Oct 6, 2016
74a9c4a
[MIG] Rename manifest files
pedrobaeza Oct 6, 2016
f5fd672
[MIG] mail_tracking_mailgun: Migrated to 10.0
bouvyd Oct 14, 2016
e15dbc1
OCA Transbot updated translations from Transifex
oca-transbot Nov 29, 2016
940bc72
Add Contributors
rafaelbn Mar 14, 2017
c043345
OCA Transbot updated translations from Transifex
oca-transbot May 20, 2017
a584348
[IMP] mute logger on tests error responses so Travis doesn't fail
chienandalu Jul 14, 2017
fd4c967
OCA Transbot updated translations from Transifex
oca-transbot Jul 22, 2017
58aab07
[10.0][IMP] mail_tracking_mailgun: add partner mail checks
chienandalu Oct 17, 2017
3ce1442
OCA Transbot updated translations from Transifex
oca-transbot Dec 2, 2017
5178721
[10.0][FIX] mail_tracking_mailgun: Avoid key dict errors
chienandalu Dec 22, 2017
3df3eca
[FIX] mail_tracking_mailgun: Avoid errors without event
yajo Jan 15, 2018
240b725
OCA Transbot updated translations from Transifex
oca-transbot Jan 16, 2018
dcd0548
[FIX] mail_tracking_mailgun: Message error on bounce
pedrobaeza Feb 1, 2018
0edacfb
[FIX] mail_tracking_mailgun: manual sync gets events from other recip…
chienandalu Feb 15, 2018
278f429
[IMP] mail_tracking_mailgun: validation auto check
chienandalu Feb 16, 2018
53d0944
OCA Transbot updated translations from Transifex
oca-transbot Mar 3, 2018
90f8683
[MIG] mail_tracking_mailgun: Migration to 11.0
chienandalu May 8, 2018
fb648d7
[11.0][FIX] mail_tracking_mailgun: Read config parameters with sudo
sergio-teruel May 30, 2018
9261192
Translated using Weblate (French)
didierdonze Jun 18, 2018
d4bdf1b
[FIX] mail_tracking_mailgun: alternative domain
chienandalu Aug 2, 2018
7a9e304
[MIG] mail_tracking_mailgun: Migration to 12.0
ernestotejeda Nov 5, 2018
139c899
[IMP] mail_tracking_mailgun: link to bounce event
chienandalu Sep 5, 2019
d3205c6
Translated using Weblate (Portuguese)
pedrocs-exo Mar 2, 2020
fb937be
[ADD] mail_tracking_mailgun: manage failed state from mailgun
zaoral Aug 26, 2019
40ea22f
Translated using Weblate (Slovenian)
sysadminmatmoz Mar 30, 2020
2101813
[IMP] mail_tracking_mailgun: black, isort
HviorForgeFlow Apr 2, 2020
62c1681
[MIG] mail_tracking_mailgun: Migration to 13.0
HviorForgeFlow Apr 2, 2020
3218cac
[FIX] import mock the python3 way
hbrunn Jul 29, 2020
b250d7b
[IMP] pre-commit run -a
Jan 26, 2021
4521ba9
[IMP] Apply pre-commit changes: Resolve conflicts
Tardo Jan 26, 2021
1439023
[MIG] mail_tracking_mailgun: Migration to v14.0
CarlosRoca13 Jul 22, 2021
72bf170
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Oct 28, 2021
71b36e7
[MIG] mail_tracking_mailgun: Migration to 15.0
nicomacr May 17, 2022
5ded857
[IMP] mail_tracking_mailgun: mass mailing manual tracking
chienandalu Jan 12, 2023
34205fb
[FIX] mail_tracking_mailgun: bounces error
chienandalu Jul 26, 2023
0321236
Translated using Weblate (Spanish)
Ivorra78 Oct 19, 2023
980a688
[MIG] mail_tracking_mailgun: Migration to 16.0
alan196 Feb 20, 2023
a8eceb5
[FIX/IMP] mail_tracking_mailgun: finish migration
chienandalu Oct 31, 2023
344b748
Translated using Weblate (Italian)
mymage Dec 11, 2023
85c3607
Translated using Weblate (French)
vincent-hatakeyama Feb 23, 2024
a4cb547
[FIX] mail_tracking_mailgun: discard non Odoo events
chienandalu Jul 11, 2024
895aa9f
[IMP] mail_tracking_mailgun: black, isort, prettier
chienandalu Jul 5, 2024
c653846
[MIG] mail_tracking_mailgun: Migration to 17.0
chienandalu Jul 5, 2024
cb4a515
[FIX] mail_tracking_mailgun: Markup link
pedrobaeza Apr 17, 2025
4f92db4
[IMP] mail_tracking_mailgun: pre-commit stuff
pedrobaeza Jun 29, 2025
867b5a3
[MIG] mail_tracking_mailgun: Migration to 18.0
pedrobaeza Jun 29, 2025
b6c8b7e
[UPD] Update mail_tracking_mailgun.pot
Jun 30, 2025
d30faad
[BOT] post-merge updates
OCA-git-bot Jun 30, 2025
51297b2
[IMP] mail_tracking_mailgun: pre-commit auto fixes
JasminSForgeFlow Feb 26, 2026
488106c
[MIG] mail_tracking_mailgun: Migration to 19.0
JasminSForgeFlow Feb 26, 2026
ac6e512
[DON'T MERGE] test-requirements.txt
JasminSForgeFlow Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions mail_tracking_mailgun/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========================
Mail tracking for Mailgun
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:baa0b4cccd7ccebd5e3197b70a46ebb3d4c454734f06fb190cf74775b5bce75f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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%2Fmail-lightgray.png?logo=github
:target: https://github.com/OCA/mail/tree/19.0/mail_tracking_mailgun
:alt: OCA/mail
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/mail-19-0/mail-19-0-mail_tracking_mailgun
: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/mail&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module integrates mail_tracking events with Mailgun webhooks.

`Mailgun <https://www.mailgun.com>`__ is a service that provides an
e-mail sending infrastructure through an SMTP server or via API. You can
also query that API for seeing statistics of your sent e-mails, or
provide hooks that processes the status changes in real time, which is
the function used here.

**Table of contents**

.. contents::
:local:

Installation
============

If you're using a multi-database installation (with or without dbfilter
option) where /web/databse/selector returns a list of more than one
database, then you need to add ``mail_tracking_mailgun`` addon to wide
load addons list (by default, only ``web`` addon), setting ``--load``
option.

Example: ``--load=web,mail_tracking,mail_tracking_mailgun``

Configuration
=============

To configure this module, you need to:

1. Go to Mailgun, create an account and validate your sending domain.
2. Go back to Odoo.
3. Go to *Settings > General Settings > Discuss > Enable mail tracking
with Mailgun*.
4. Fill all the values. The only one required is the API key.
5. Optionally click *Unregister Mailgun webhooks* and accept.
6. Click *Register Mailgun webhooks*.

You can also config timeout for mailgun with this system parameter:

- ``mailgun.timeout``: Set it to a number of seconds.

Usage
=====

In your mail tracking status screens (explained on module
*mail_tracking*), you will see a more accurate information, like the
'Received' or 'Bounced' status, which are not usually detected by normal
SMTP servers.

It's also possible to make some checks to the partner's email addresses
against the Mailgun API:

- Check if the partner's email is in Mailgun's bounced list.
- Check the validity of the partner's mailbox.
- Force the partner's email into Mailgun's bounced list or delete from
it.

It's also possible to manually check a message mailgun tracking when the
webhook couldn't be captured. For that, go to that message tracking
form, press the button *Check Mailgun*. It's important to note that
tracking events have quite a short lifespan, so after 24h they won't be
recoverable.

Known issues / Roadmap
======================

- There's no support for more than one Mailgun mail server.
- Automate more webhook registration. It would be nice to not have to
click the "Unregister Mailgun webhooks" and "Register Mailgun
webhooks" when setting up Mailgun in Odoo. However, it doesn't come
without its `conceptual
complexities <https://github.com/OCA/social/pull/787#discussion_r734275262>`__.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/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 <https://github.com/OCA/mail/issues/new?body=module:%20mail_tracking_mailgun%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Tecnativa

Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:

- Antonio Espinosa
- Carlos Dauden
- Pedro M. Baeza
- David Vidal
- Rafael Blasco
- Ernesto Tejeda
- Jairo Llopis
- Carlos Roca

Other credits
-------------

Images
~~~~~~

- Mailgun logo: `SVG
Icon <http://seeklogo.com/mailgun-logo-273630.html>`__.

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/mail <https://github.com/OCA/mail/tree/19.0/mail_tracking_mailgun>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions mail_tracking_mailgun/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import controllers
from . import models
from . import wizards
22 changes: 22 additions & 0 deletions mail_tracking_mailgun/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2016 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Carlos Dauden
# Copyright 2017 Tecnativa - David Vidal
# Copyright 2017,2025 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Mail tracking for Mailgun",
"summary": "Mail tracking and Mailgun webhooks integration",
"version": "19.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/mail",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["mail_tracking"],
"data": [
"views/res_partner.xml",
"views/mail_tracking_email.xml",
"wizards/res_config_settings_views.xml",
],
}
1 change: 1 addition & 0 deletions mail_tracking_mailgun/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
75 changes: 75 additions & 0 deletions mail_tracking_mailgun/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2021 Tecnativa - Jairo Llopis
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import hashlib
import hmac
import logging
from datetime import datetime, timedelta

from werkzeug.exceptions import NotAcceptable

from odoo.exceptions import ValidationError
from odoo.http import request, route

from odoo.addons.web.controllers.utils import ensure_db

from ...mail_tracking.controllers import main

_logger = logging.getLogger(__name__)


class MailTrackingController(main.MailTrackingController):
def _mail_tracking_mailgun_webhook_verify(self, timestamp, token, signature):
"""Avoid mailgun webhook attacks.

See https://documentation.mailgun.com/en/latest/user_manual.html#securing-webhooks
""" # noqa: E501
# Request cannot be old
processing_time = datetime.utcnow() - datetime.utcfromtimestamp(int(timestamp))
if not timedelta() < processing_time < timedelta(minutes=10):
raise ValidationError(request.env._("Request is too old"))
# Avoid replay attacks
try:
processed_tokens = (
request.env.registry._mail_tracking_mailgun_processed_tokens
)
except AttributeError:
processed_tokens = (
request.env.registry._mail_tracking_mailgun_processed_tokens
) = set()
if token in processed_tokens:
raise ValidationError(request.env._("Request was already processed"))
processed_tokens.add(token)
params = request.env["mail.tracking.email"]._mailgun_values()
# Assert signature
if not params.webhook_signing_key:
_logger.warning(
"Skipping webhook payload verification. "
"Set `mailgun.webhook_signing_key` config parameter to enable"
)
return
hmac_digest = hmac.new(
key=params.webhook_signing_key.encode(),
msg=(f"{timestamp}{token}").encode(),
digestmod=hashlib.sha256,
).hexdigest()
if not hmac.compare_digest(str(signature), str(hmac_digest)):
raise ValidationError(request.env._("Wrong signature"))

@route(["/mail/tracking/mailgun/all"], auth="none", type="jsonrpc", csrf=False)
def mail_tracking_mailgun_webhook(self):
"""Process webhooks from Mailgun."""
ensure_db()
# Verify and return 406 in case of failure, to avoid retries
# See https://documentation.mailgun.com/en/latest/user_manual.html#routes
try:
self._mail_tracking_mailgun_webhook_verify(
**request.dispatcher.jsonrequest["signature"]
)
except ValidationError as error:
raise NotAcceptable from error
# Process event
request.env["mail.tracking.email"].sudo()._mailgun_event_process(
request.dispatcher.jsonrequest["event-data"],
self._request_metadata(),
)
Loading
Loading