Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] mail_tracking_mailgun: Migration to 15.0 #909

Merged
merged 44 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e739bd5
OCA Transbot updated translations from Transifex
antespi Sep 19, 2016
708b72f
[ADD] mail_tracking_mailgun
antespi Jul 15, 2016
b56ff37
[8.0][IMP][mail_tracking] Speed installation time and discard concurr…
antespi Sep 9, 2016
6f62314
[MIG] mail_tracking_mailgun
antespi Sep 13, 2016
21e3cb5
[MIG] Make modules uninstallable
pedrobaeza Oct 6, 2016
9adb6bd
[MIG] Rename manifest files
pedrobaeza Oct 6, 2016
24e5044
[MIG] mail_tracking_mailgun: Migrated to 10.0
bouvyd Oct 14, 2016
b2ecc17
OCA Transbot updated translations from Transifex
oca-transbot Nov 29, 2016
003d7d8
Add Contributors
rafaelbn Mar 14, 2017
a757066
OCA Transbot updated translations from Transifex
oca-transbot May 20, 2017
ed9b469
[IMP] mute logger on tests error responses so Travis doesn't fail
chienandalu Jul 14, 2017
3e82735
OCA Transbot updated translations from Transifex
oca-transbot Jul 22, 2017
3ca3ee4
[10.0][IMP] mail_tracking_mailgun: add partner mail checks
chienandalu Oct 17, 2017
11f1664
OCA Transbot updated translations from Transifex
oca-transbot Dec 2, 2017
112ed9a
[10.0][FIX] mail_tracking_mailgun: Avoid key dict errors
chienandalu Dec 22, 2017
a43bfa8
[FIX] mail_tracking_mailgun: Avoid errors without event
yajo Jan 15, 2018
ed69644
OCA Transbot updated translations from Transifex
oca-transbot Jan 16, 2018
07e9a8a
[FIX] mail_tracking_mailgun: Message error on bounce
pedrobaeza Feb 1, 2018
bf01a33
[FIX] mail_tracking_mailgun: manual sync gets events from other recip…
chienandalu Feb 15, 2018
88f0f2d
[IMP] mail_tracking_mailgun: validation auto check
chienandalu Feb 16, 2018
02d0c30
OCA Transbot updated translations from Transifex
oca-transbot Mar 3, 2018
ccee125
[MIG] mail_tracking_mailgun: Migration to 11.0
chienandalu May 8, 2018
3deee37
[11.0][FIX] mail_tracking_mailgun: Read config parameters with sudo
sergio-teruel May 30, 2018
bf4687c
Translated using Weblate (French)
didierdonze Jun 18, 2018
85beba2
[FIX] mail_tracking_mailgun: alternative domain
chienandalu Aug 2, 2018
47dac3e
[MIG] mail_tracking_mailgun: Migration to 12.0
ernestotejeda Nov 5, 2018
167d035
[IMP] mail_tracking_mailgun: link to bounce event
chienandalu Sep 5, 2019
563945a
Translated using Weblate (Portuguese)
pedrocs-exo Mar 2, 2020
573181b
[ADD] mail_tracking_mailgun: manage failed state from mailgun
zaoral Aug 26, 2019
6ca2da2
Translated using Weblate (Slovenian)
sysadminmatmoz Mar 30, 2020
5892f7d
[IMP] mail_tracking_mailgun: black, isort
HviorForgeFlow Apr 2, 2020
ee8c5c5
[MIG] mail_tracking_mailgun: Migration to 13.0
HviorForgeFlow Apr 2, 2020
8e09f81
[FIX] import mock the python3 way
hbrunn Jul 29, 2020
7186f72
[IMP] pre-commit run -a
Jan 26, 2021
de323bd
[IMP] Apply pre-commit changes: Resolve conflicts
Tardo Jan 26, 2021
28d15c4
[MIG] mail_tracking_mailgun: Migration to v14.0
CarlosRoca13 Jul 22, 2021
4dfe599
[UPD] Update mail_tracking_mailgun.pot
oca-travis Jul 28, 2021
f0df46b
[UPD] README.rst
OCA-git-bot Jul 28, 2021
9983651
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Oct 28, 2021
033dd69
[UPD] Update mail_tracking_mailgun.pot
oca-travis Feb 25, 2022
08281b3
[UPD] README.rst
OCA-git-bot Feb 25, 2022
fbc7399
Update translation files
oca-transbot Feb 25, 2022
df3453c
[IMP] mail_tracking_mailgun: pre-commit execution
nicomacr May 17, 2022
d2792da
[MIG] mail_tracking_mailgun: Migration to 15.0
nicomacr May 17, 2022
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
151 changes: 151 additions & 0 deletions mail_tracking_mailgun/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
=========================
Mail tracking for Mailgun
=========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/14.0/mail_tracking_mailgun
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_tracking_mailgun
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/205/14.0
:alt: Try me on Runbot

|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:

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

You can also config partner email autocheck with this system parameter:

- `mailgun.auto_check_partner_email`: Set it to True.

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/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 <https://github.com/OCA/social/issues/new?body=module:%20mail_tracking_mailgun%0Aversion:%2014.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/social <https://github.com/OCA/social/tree/14.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 - Pedro M. Baeza
# Copyright 2017-18 Tecnativa - David Vidal
# 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": "15.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"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 import _
from odoo.exceptions import ValidationError
from odoo.http import request, route

from ...mail_tracking.controllers import main
from ...web.controllers.main import ensure_db

_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 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 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=("{}{}".format(timestamp, token)).encode(),
digestmod=hashlib.sha256,
).hexdigest()
if not hmac.compare_digest(str(signature), str(hmac_digest)):
raise ValidationError(_("Wrong signature"))

@route(["/mail/tracking/mailgun/all"], auth="none", type="json", 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.jsonrequest["signature"]
)
except ValidationError as error:
raise NotAcceptable from error
# Process event
request.env["mail.tracking.email"].sudo()._mailgun_event_process(
request.jsonrequest["event-data"],
self._request_metadata(),
)
Loading