forked from akretion/ak-odoo-incubator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request akretion#198 from akretion/12.0-mig-mail_via
[12.0] [MIG] mail_via
- Loading branch information
Showing
8 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import ir_mail_server | ||
from . import mail_mail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |