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_mass_mailing: migrate module to v15.0 task#16703 #1

Open
wants to merge 45 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c15906b
OCA Transbot updated translations from Transifex
antespi Sep 19, 2016
90e5224
[ADD] mail_tracking_mailgun
antespi Jul 15, 2016
54fae27
[8.0][IMP][mail_tracking] Speed installation time and discard concurr…
antespi Sep 9, 2016
2f794e1
[MIG] mail_tracking_mailgun
antespi Sep 13, 2016
9195852
[MIG] Make modules uninstallable
pedrobaeza Oct 6, 2016
9c69434
[MIG] Rename manifest files
pedrobaeza Oct 6, 2016
11490ba
[MIG] mail_tracking_mailgun: Migrated to 10.0
bouvyd Oct 14, 2016
0b4dffb
OCA Transbot updated translations from Transifex
oca-transbot Nov 29, 2016
8169730
Add Contributors
rafaelbn Mar 14, 2017
ce1f4a1
OCA Transbot updated translations from Transifex
oca-transbot May 20, 2017
536bf7e
[IMP] mute logger on tests error responses so Travis doesn't fail
chienandalu Jul 14, 2017
f95fc8a
OCA Transbot updated translations from Transifex
oca-transbot Jul 22, 2017
fe8e1d4
[10.0][IMP] mail_tracking_mailgun: add partner mail checks
chienandalu Oct 17, 2017
b601a6d
OCA Transbot updated translations from Transifex
oca-transbot Dec 2, 2017
a353a71
[10.0][FIX] mail_tracking_mailgun: Avoid key dict errors
chienandalu Dec 22, 2017
4373e55
[FIX] mail_tracking_mailgun: Avoid errors without event
yajo Jan 15, 2018
d429005
OCA Transbot updated translations from Transifex
oca-transbot Jan 16, 2018
5f9d65b
[FIX] mail_tracking_mailgun: Message error on bounce
pedrobaeza Feb 1, 2018
3040bbf
[FIX] mail_tracking_mailgun: manual sync gets events from other recip…
chienandalu Feb 15, 2018
ddf73bf
[IMP] mail_tracking_mailgun: validation auto check
chienandalu Feb 16, 2018
e4ed59f
OCA Transbot updated translations from Transifex
oca-transbot Mar 3, 2018
b591ae2
[MIG] mail_tracking_mailgun: Migration to 11.0
chienandalu May 8, 2018
c711bab
[11.0][FIX] mail_tracking_mailgun: Read config parameters with sudo
sergio-teruel May 30, 2018
3c793ca
Translated using Weblate (French)
didierdonze Jun 18, 2018
4aaf441
[FIX] mail_tracking_mailgun: alternative domain
chienandalu Aug 2, 2018
6ecad6c
[MIG] mail_tracking_mailgun: Migration to 12.0
ernestotejeda Nov 5, 2018
32abcfa
[IMP] mail_tracking_mailgun: link to bounce event
chienandalu Sep 5, 2019
9cbfbdb
Translated using Weblate (Portuguese)
pedrocs-exo Mar 2, 2020
83233ef
[ADD] mail_tracking_mailgun: manage failed state from mailgun
zaoral Aug 26, 2019
8bb7339
Translated using Weblate (Slovenian)
sysadminmatmoz Mar 30, 2020
f077ace
[IMP] mail_tracking_mailgun: black, isort
HviorForgeFlow Apr 2, 2020
5cb899e
[MIG] mail_tracking_mailgun: Migration to 13.0
HviorForgeFlow Apr 2, 2020
6138d2f
[FIX] import mock the python3 way
hbrunn Jul 29, 2020
7940e89
[IMP] pre-commit run -a
Jan 26, 2021
9947d3e
[IMP] Apply pre-commit changes: Resolve conflicts
Tardo Jan 26, 2021
44a0cbc
[MIG] mail_tracking_mailgun: Migration to v14.0
CarlosRoca13 Jul 22, 2021
54098c9
[UPD] Update mail_tracking_mailgun.pot
oca-travis Jul 28, 2021
3ff0a76
[UPD] README.rst
OCA-git-bot Jul 28, 2021
8ca55b0
[IMP] mail_tracking_mailgun: refactor to support modern webhooks
Oct 28, 2021
de46ad8
[UPD] Update mail_tracking_mailgun.pot
oca-travis Feb 25, 2022
bab6364
[UPD] README.rst
OCA-git-bot Feb 25, 2022
c8b509b
Update translation files
oca-transbot Feb 25, 2022
bb584e7
[MIG] : Migration to 15.0
alan196 Apr 20, 2022
5d5c815
[MIG] mail_tracking_mailgun: Migration to 15.0
alan196 Apr 20, 2022
1a5e3b8
[mig] mail_tracking_mass_mailing: migrate module to v15.0 task#16703
Sep 22, 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"))

Check warning on line 30 in mail_tracking_mailgun/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

mail_tracking_mailgun/controllers/main.py#L30

Added line #L30 was not covered by tests
# 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"))

Check warning on line 41 in mail_tracking_mailgun/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

mail_tracking_mailgun/controllers/main.py#L41

Added line #L41 was not covered by tests
processed_tokens.add(token)
params = request.env["mail.tracking.email"]._mailgun_values()
# Assert signature
if not params.webhook_signing_key:
_logger.warning(

Check warning on line 46 in mail_tracking_mailgun/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

mail_tracking_mailgun/controllers/main.py#L46

Added line #L46 was not covered by tests
"Skipping webhook payload verification. "
"Set `mailgun.webhook_signing_key` config parameter to enable"
)
return

Check warning on line 50 in mail_tracking_mailgun/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

mail_tracking_mailgun/controllers/main.py#L50

Added line #L50 was not covered by tests
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