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

[16.0][MIG] mail_server_by_user: Migration to 16.0 #1422

Open
wants to merge 13 commits into
base: 16.0
Choose a base branch
from
91 changes: 91 additions & 0 deletions mail_server_by_user/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
====================
Email Server By User
====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9313575d1d36133e0993e203d53247a3beb4122f34e111c8418dfb07f57733c8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/16.0/mail_server_by_user
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_server_by_user
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Change SMTP server with smtp_user equal email of
user perform mail actions, like message_post, mail.mail send, and base email sending

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_server_by_user%0Aversion:%2016.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
~~~~~~~

* ForgeFlow

Contributors
~~~~~~~~~~~~

* Christopher Ormaza <[email protected]>
* `Onestein <https://www.onestein.eu>`__

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.

.. |maintainer-ChrisOForgeFlow| image:: https://github.com/ChrisOForgeFlow.png?size=40px
:target: https://github.com/ChrisOForgeFlow
:alt: ChrisOForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ChrisOForgeFlow|

This module is part of the `OCA/social <https://github.com/OCA/social/tree/16.0/mail_server_by_user>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mail_server_by_user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions mail_server_by_user/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2022 ForgeFlow S.L. (https://forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Email Server By User",
"summary": "Email Server By User",
"version": "16.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": ("ForgeFlow, " "Odoo Community Association (OCA)"),
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": ["base", "mail"],
"development_status": "Alpha",
"maintainers": ["ChrisOForgeFlow"],
"data": [],
"qweb": [],
"demo": [],
}
61 changes: 61 additions & 0 deletions mail_server_by_user/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_server_by_user
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-01-28 11:33+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server__display_name
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail__display_name
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread__display_name
msgid "Display Name"
msgstr "Mostrar Nombre"

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_mail_thread
msgid "Email Thread"
msgstr "Hilo de Correo Electrónico"

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server__id
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail__id
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread__id
msgid "ID"
msgstr "ID"

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server____last_update
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail____last_update
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread____last_update
msgid "Last Modified on"
msgstr "Última Modificación el"

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_ir_mail_server
msgid "Mail Server"
msgstr "Servidor de Correo"

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_mail_mail
msgid "Outgoing Mails"
msgstr "Correos Salientes"

#. module: mail_server_by_user
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#, python-format
msgid "Test"
msgstr "Prueba"
61 changes: 61 additions & 0 deletions mail_server_by_user/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_server_by_user
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-01-20 22:33+0000\n"
"Last-Translator: Claude R Perrin <[email protected]>\n"
"Language-Team: none\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n > 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server__display_name
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail__display_name
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread__display_name
msgid "Display Name"
msgstr "Nom affiché"

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_mail_thread
msgid "Email Thread"
msgstr "Flux Email"

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server__id
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail__id
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread__id
msgid "ID"
msgstr "ID"

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server____last_update
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail____last_update
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_ir_mail_server
msgid "Mail Server"
msgstr "Serveur de messagerie"

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_mail_mail
msgid "Outgoing Mails"
msgstr "Emails sortants"

#. module: mail_server_by_user
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#, python-format
msgid "Test"
msgstr "Test"
58 changes: 58 additions & 0 deletions mail_server_by_user/i18n/mail_server_by_user.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_server_by_user
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server__display_name
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail__display_name
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread__display_name
msgid "Display Name"
msgstr ""

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_mail_thread
msgid "Email Thread"
msgstr ""

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server__id
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail__id
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread__id
msgid "ID"
msgstr ""

#. module: mail_server_by_user
#: model:ir.model.fields,field_description:mail_server_by_user.field_ir_mail_server____last_update
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_mail____last_update
#: model:ir.model.fields,field_description:mail_server_by_user.field_mail_thread____last_update
msgid "Last Modified on"
msgstr ""

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_ir_mail_server
msgid "Mail Server"
msgstr ""

#. module: mail_server_by_user
#: model:ir.model,name:mail_server_by_user.model_mail_mail
msgid "Outgoing Mails"
msgstr ""

#. module: mail_server_by_user
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#: code:addons/mail_server_by_user/tests/test_mail_server_by_user.py:0
#, python-format
msgid "Test"
msgstr ""
3 changes: 3 additions & 0 deletions mail_server_by_user/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import ir_mail_server
from . import mail_mail
from . import mail_thread
44 changes: 44 additions & 0 deletions mail_server_by_user/models/ir_mail_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2022 ForgeFlow S.L. (https://forgeflow.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
from odoo.tools.mail import email_normalize


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

@api.model
def send_email(
self,
message,
mail_server_id=None,
smtp_server=None,
smtp_port=None,
smtp_user=None,
smtp_password=None,
smtp_encryption=None,
smtp_ssl_certificate=None,
smtp_ssl_private_key=None,
smtp_debug=False,
smtp_session=None,
):
email_from = message["From"]
if email_from:
mail_server_suggested = self.search(
[("smtp_user", "=", email_normalize(email_from))], limit=1
)
if mail_server_suggested:
mail_server_id = mail_server_suggested.id
return super().send_email(
message,
mail_server_id=mail_server_id,
smtp_server=smtp_server,
smtp_port=smtp_port,
smtp_user=smtp_user,
smtp_password=smtp_password,
smtp_encryption=smtp_encryption,
smtp_ssl_certificate=smtp_ssl_certificate,
smtp_ssl_private_key=smtp_ssl_private_key,
smtp_debug=smtp_debug,
smtp_session=smtp_session,
)
26 changes: 26 additions & 0 deletions mail_server_by_user/models/mail_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2022 ForgeFlow S.L. (https://forgeflow.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
from odoo.tools.mail import email_normalize


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

def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
mail_server_model = self.env["ir.mail_server"].sudo()
for rec in self:
if rec.email_from:
mail_server_suggested = mail_server_model.search(
[("smtp_user", "=", email_normalize(rec.email_from))], limit=1
)
if (
mail_server_suggested
and rec.mail_server_id.id != mail_server_suggested.id
):
rec.mail_server_id = mail_server_suggested.id
return super(MailMail, self)._send(
auto_commit=auto_commit,
raise_exception=raise_exception,
smtp_session=smtp_session,
)
Loading
Loading