golem/golem_base/models/ir_mail_server.py

48 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2018-2020 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""IR Mail Server fix for >64 characters pass """
from odoo import models, fields
class IrMailServer(models.Model):
""" IR Mail Server adaptations """
_inherit = 'ir.mail_server'
# IR Mail Server fix for >64 characters pass
smtp_user = fields.Char(size=100)
smtp_pass = fields.Char(size=100)
def build_email(self, email_from, email_to, subject, body, email_cc=None,
email_bcc=None, reply_to=False, attachments=None,
message_id=None, references=None, object_id=False,
subtype='plain', headers=None, body_alternative=None,
subtype_alternative='plain'):
""" Overwrite to supercharge from_to """
get_param = self.env['ir.config_parameter'].sudo().get_param
force_email_from = get_param('mail.force.email_from', email_from)
if force_email_from != email_from:
email_from = force_email_from
reply_to = force_email_from
msg = super(IrMailServer, self).build_email(
email_from, email_to, subject, body, email_cc, email_bcc,
reply_to, attachments, message_id, references, object_id, subtype,
headers, body_alternative, subtype_alternative
)
return msg