Skip to content

Commit

Permalink
Merge pull request akretion#198 from akretion/12.0-mig-mail_via
Browse files Browse the repository at this point in the history
[12.0] [MIG] mail_via
  • Loading branch information
sebastienbeau authored Apr 4, 2022
2 parents 8222912 + 87ab208 commit c292e1e
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ install:
${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
- git clone https://github.com/akretion/akretion-quality-tools ${HOME}/akretion-quality-tools
- export PATH=${HOME}/akretion-quality-tools/travis:${PATH}
- travis_configure

script:
- travis_run_tests
Expand Down
17 changes: 17 additions & 0 deletions mail_via/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

==============
Mail Via
==============

When importing email from incoming gateway and sending back them to follower.
Odoo set in the original sender in the from message. With email provider like mailjet, the mail is not accepted as we do not have the right to send an email with the original sender.

This module will change the FROM with a "via" address and use as name the name with the email of the sender

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

* Sébastien BEAU <[email protected]>
1 change: 1 addition & 0 deletions mail_via/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions mail_via/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2019 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Mail Via",
"summary": "Change the from email with via email when sending back email",
"version": "12.0.1.0.0",
"category": "Mail",
"website": "www.akretion.com",
"author": " Akretion",
"license": "AGPL-3",
"depends": ["mail"],
"data": ["data/mail_data.xml"],
"installable": True,
}
10 changes: 10 additions & 0 deletions mail_via/data/mail_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">

<!-- Via Email Alias -->
<record id="icp_mail_via_alias" model="ir.config_parameter">
<field name="key">mail.via.alias</field>
<field name="value">via</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions mail_via/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_mail_server
from . import mail_mail
21 changes: 21 additions & 0 deletions mail_via/models/ir_mail_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2019 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class IrMailServer(models.Model):
_inherit = "ir.mail_server"

def build_email(self, email_from, email_to, subject, body, **kwargs):
if self._context.get("sender_is_via"):
via = self.env["ir.config_parameter"].get_param("mail.via.alias")
domain = self.env["ir.config_parameter"].get_param(
"mail.catchall.domain"
)
original_from = email_from.replace("<", '"').replace(">", '"')
email_from = "{} <{}@{}>".format(original_from, via, domain)
return super(IrMailServer, self).build_email(
email_from, email_to, subject, body, **kwargs
)
21 changes: 21 additions & 0 deletions mail_via/models/mail_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2019 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, api


class MailMail(models.Model):
_inherit = "mail.mail"

@api.multi
def send(self, auto_commit=False, raise_exception=False):
incoming_mails = self.filtered("fetchmail_server_id")
super(MailMail, incoming_mails.with_context(sender_is_via=True)).send(
auto_commit=auto_commit, raise_exception=raise_exception
)
normal_mails = self.filtered(lambda s: not s.fetchmail_server_id)
super(MailMail, normal_mails).send(
auto_commit=auto_commit, raise_exception=raise_exception
)
return True

0 comments on commit c292e1e

Please sign in to comment.