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

[12.0] [MIG] mail_via #198

Merged
merged 8 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
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 <sebastien.beau@akretion.com>
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 <sebastien.beau@akretion.com>
# 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 <sebastien.beau@akretion.com>
# 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 <sebastien.beau@akretion.com>
# 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