Browse Source

[ADD] mail_from_force module

Allow to force the Sender / From address to a fixed email address.
This is needed for SMTP servers that enforce the Sender and From to be
the same user as the one connected to the SMTP server.
pull/309/head
Daniel Reis 6 years ago
parent
commit
00f837db84
  1. 2
      mail_from_force/__init__.py
  2. 23
      mail_from_force/__openerp__.py
  3. 2
      mail_from_force/models/__init__.py
  4. 27
      mail_from_force/models/ir_mail_server.py

2
mail_from_force/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

23
mail_from_force/__openerp__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
{
'name': "Force From sender to be the Admin user",
'author': "Daniel Reis,Odoo Community Association (OCA)",
'summary': 'Force the header Sender and envelope From '
'to a fixed outgoing address.',
'description': """
Sends all outgoing emails from the same fixed email address.
The email address to use is configured in the
System parameter "mail.from.force".
This email is used in the email from, along with the
actual name of the user triggering the email.
For more details on why this may be needed, see:
https://github.com/odoo/odoo/issues/3347
""",
'category': 'Mail',
'version': '8.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'mail',
],
}

2
mail_from_force/models/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import ir_mail_server

27
mail_from_force/models/ir_mail_server.py

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# © 2018 Daniel Reis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, SUPERUSER_ID
class MailServer(models.Model):
_inherit = 'ir.mail_server'
def send_email(self, cr, uid, message, mail_server_id=None,
smtp_server=None, smtp_port=None,
smtp_user=None, smtp_password=None,
smtp_encryption=None, smtp_debug=False,
context=None):
from_force = self.pool['ir.config_parameter'].get_param(
cr, SUPERUSER_ID, 'mail.from.force', context=context)
if from_force:
message['Return-Path'] = from_force
message['From'] = from_force
return super(MailServer, self).send_email(
cr, uid, message, mail_server_id,
smtp_server, smtp_port,
smtp_user, smtp_password,
smtp_encryption, smtp_debug,
context=context)
Loading…
Cancel
Save