[MERGE][IMP] mass_mailing: allow to choose outgoing server for mailings
This merge improves mass mailing application by allowing to choose specific outgoing mail servers on mailings. It is used notably if you want to separate mass mailings from classic emails and/or to perform some load balancing. A settings to add a default server used for mailings is also added. As a read access on outgoing mail servers is added for mass mailing users the credentials are now restriected to admins for security reasons. This merge is related to task ID 31737. Closes #21699 .
This commit is contained in:
@@ -6,6 +6,7 @@ import hmac
|
||||
import logging
|
||||
import random
|
||||
import threading
|
||||
from ast import literal_eval
|
||||
|
||||
from odoo import api, fields, models, tools, _
|
||||
from odoo.exceptions import UserError
|
||||
@@ -360,6 +361,15 @@ class MassMailing(models.Model):
|
||||
_inherits = {'utm.source': 'source_id'}
|
||||
_rec_name = "source_id"
|
||||
|
||||
@api.model
|
||||
def _get_default_mail_server_id(self):
|
||||
server_id = self.env['ir.config_parameter'].sudo().get_param('mass_mailing.mail_server_id')
|
||||
try:
|
||||
server_id = literal_eval(server_id) if server_id else False
|
||||
return self.env['ir.mail_server'].search([('id', '=', server_id)]).id
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(MassMailing, self).default_get(fields)
|
||||
@@ -403,6 +413,9 @@ class MassMailing(models.Model):
|
||||
default=lambda self: self.env.ref('mass_mailing.model_mail_mass_mailing_list').id)
|
||||
mailing_model_name = fields.Char(related='mailing_model_id.model', string='Recipients Model Name', readonly=True, related_sudo=True)
|
||||
mailing_domain = fields.Char(string='Domain', oldname='domain', default=[])
|
||||
mail_server_id = fields.Many2one('ir.mail_server', string='Mail Server',
|
||||
default=_get_default_mail_server_id,
|
||||
help="Use a specific mail server in priority. Otherwise Odoo relies on the first outgoing mail server available (based on their sequencing) as it does for normal mails.")
|
||||
contact_list_ids = fields.Many2many('mail.mass_mailing.list', 'mail_mass_mailing_list_rel',
|
||||
string='Mailing Lists')
|
||||
contact_ab_pc = fields.Integer(string='A/B Testing percentage',
|
||||
@@ -760,6 +773,7 @@ class MassMailing(models.Model):
|
||||
'mass_mailing_id': mailing.id,
|
||||
'mailing_list_ids': [(4, l.id) for l in mailing.contact_list_ids],
|
||||
'no_auto_thread': mailing.reply_to_mode != 'thread',
|
||||
'mail_server_id': mailing.mail_server_id.id,
|
||||
}
|
||||
if mailing.reply_to_mode == 'email':
|
||||
composer_values['reply_to'] = mailing.reply_to
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
group_mass_mailing_campaign = fields.Boolean(string="Mass Mailing Campaigns", implied_group='mass_mailing.group_mass_mailing_campaign', help="""This is useful if your marketing campaigns are composed of several emails""")
|
||||
mass_mailing_outgoing_mail_server = fields.Boolean(string="Specific Mail Server", config_parameter='mass_mailing.outgoing_mail_server',
|
||||
help='Use a specific mail server in priority. Otherwise Odoo relies on the first outgoing mail server available (based on their sequencing) as it does for normal mails.')
|
||||
mass_mailing_mail_server_id = fields.Many2one('ir.mail_server', string='Mail Server', config_parameter='mass_mailing.mail_server_id')
|
||||
|
||||
@api.onchange('mass_mailing_outgoing_mail_server')
|
||||
def _onchange_mass_mailing_outgoing_mail_server(self):
|
||||
if not self.mass_mailing_outgoing_mail_server:
|
||||
self.mass_mailing_mail_server_id = False
|
||||
|
||||
@@ -10,4 +10,5 @@ access_mass_mailing_system,mail.mass_mailing.system,model_mail_mass_mailing,base
|
||||
access_mail_mail_statistics_user,mail.mail.statistics,model_mail_mail_statistics,base.group_user,1,1,1,1
|
||||
access_mail_mail_statistics_mass_mailing_user,mail.mail.statistics,model_mail_mail_statistics,mass_mailing.group_mass_mailing_user,1,1,1,1
|
||||
access_mail_statistics_report,mail.statistics.report,model_mail_statistics_report,mass_mailing.group_mass_mailing_user,1,1,1,1
|
||||
access_utm_source,access_utm_source,utm.model_utm_source,mass_mailing.group_mass_mailing_user,1,1,1,0
|
||||
access_utm_source,access_utm_source,utm.model_utm_source,mass_mailing.group_mass_mailing_user,1,1,1,0
|
||||
access_ir_mail_server,access_ir_mail_server,base.model_ir_mail_server,mass_mailing.group_mass_mailing_user,1,0,0,0
|
||||
|
||||
|
@@ -531,6 +531,7 @@
|
||||
<div>
|
||||
<field name="attachment_ids" widget="many2many_binary" string="Attach a file" class="oe_inline"/>
|
||||
</div>
|
||||
<field name="mail_server_id" groups="base.group_no_one" options="{'no_create': True, 'no_open': True}"/>
|
||||
<field name="schedule_date" />
|
||||
<field name="keep_archives" groups="base.group_no_one"/>
|
||||
<field name="create_date" readonly="1" attrs="{'invisible': [('create_date', '=', False)]}"/>
|
||||
|
||||
@@ -28,6 +28,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 o_setting_box col-xs-12">
|
||||
<div class="o_setting_left_pane" title="Use a specific mail server in priority. Otherwise Odoo relies on the first outgoing mail server available (based on their sequencing) as it does for normal mails.">
|
||||
<field name="mass_mailing_outgoing_mail_server"/>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="mass_mailing_outgoing_mail_server"/>
|
||||
<div class="text-muted">
|
||||
Use a specific mail server for mailings
|
||||
</div>
|
||||
<div class="content-group" attrs="{'invisible': [('mass_mailing_outgoing_mail_server', '=', False)]}">
|
||||
<div class="mt16">
|
||||
<field name="mass_mailing_mail_server_id" options="{'no_create': True, 'no_open': True}"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h2>Mailing Lists</h2>
|
||||
<div id="mailing_list" class="row mt16 o_settings_container"/>
|
||||
|
||||
@@ -133,8 +133,8 @@ class IrMailServer(models.Model):
|
||||
name = fields.Char(string='Description', required=True, index=True)
|
||||
smtp_host = fields.Char(string='SMTP Server', required=True, help="Hostname or IP of SMTP server")
|
||||
smtp_port = fields.Integer(string='SMTP Port', size=5, required=True, default=25, help="SMTP Port. Usually 465 for SSL, and 25 or 587 for other cases.")
|
||||
smtp_user = fields.Char(string='Username', help="Optional username for SMTP authentication")
|
||||
smtp_pass = fields.Char(string='Password', help="Optional password for SMTP authentication")
|
||||
smtp_user = fields.Char(string='Username', help="Optional username for SMTP authentication", groups='base.group_system')
|
||||
smtp_pass = fields.Char(string='Password', help="Optional password for SMTP authentication", groups='base.group_system')
|
||||
smtp_encryption = fields.Selection([('none', 'None'),
|
||||
('starttls', 'TLS (STARTTLS)'),
|
||||
('ssl', 'SSL/TLS')],
|
||||
@@ -150,10 +150,6 @@ class IrMailServer(models.Model):
|
||||
"is used. Default priority is 10 (smaller number = higher priority)")
|
||||
active = fields.Boolean(default=True)
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
return [(server.id, "(%s)" % server.name) for server in self]
|
||||
|
||||
@api.multi
|
||||
def test_smtp_connection(self):
|
||||
for server in self:
|
||||
|
||||
Reference in New Issue
Block a user