When the system broadcasts an email response to document followers, if the config parameters `mail.force.smtp.from` or `mail.dynamic.smtp.from` are defined, it will rewrite the `From` address to avoid spoofing the sender's domain. **NOTE**: As of 15.0, this is based on the `from_filter` setting on the corresponding ir.mail_server, rather than the abovementioned config parameters, but the rest of the discussion stands. For example, if the `mail.catchall.domain` is set to `example.com` and an email response comes from: "John D" <john@doe.com> it will rewrite it to: "John D (john@doe.com)" <notifications@example.com> This will make sure the system never sends outgoing email for an external domain, as it has no authority for doing so, and that could break mail filtering/authentication rules (SPF, DMARC, etc.) During this "encapsulation rewrite step", both the original Sender name and their email are preserved, and put into the quoted "name" field of the rewritten address. It seems sensible to preserve as much information as possible about the original sender. Unfortunately, the inclusion of the Sender email in the final name makes it appear to some inbox providers as if the message is trying to deceptively impersonate another person (as many phishing schemes would). As of November 2021 GMail at least does this, and will hide the name in the UI when it happens. It will keep only the rewritten email, which is not very useful in the case of a notification (even though it's more technically correct, of course). This patch removes the original email from the rewritten notification, keeping only the name, considering that the email is not the most important part, and it's better to have one of the two than none. So after the patch, the rewritten address is now: "John D" <notifications@example.com> When there is no name in the original address, we keep only the local part of the email, to avoid the same display issue. The recipient will have to identify the sender based on the context / past messages. closes odoo/odoo#81807 X-original-commit: 3c65ec5a8191a392980ceb0a8c584767eae405f1 Signed-off-by: Olivier Dony <odo@odoo.com>
119 lines
5.0 KiB
Python
119 lines
5.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.test_mass_mailing.tests.common import TestMassMailCommon
|
|
from odoo.addons.base.tests.common import MockSmtplibCase
|
|
from odoo.tests import tagged
|
|
from odoo.tests.common import users
|
|
from odoo.tools import mute_logger
|
|
|
|
|
|
@tagged('mass_mailing')
|
|
class TestMassMailingServer(TestMassMailCommon, MockSmtplibCase):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(TestMassMailingServer, cls).setUpClass()
|
|
cls._init_mail_gateway()
|
|
cls.env['ir.mail_server'].search([]).unlink()
|
|
cls._init_mail_servers()
|
|
cls.recipients = cls._create_mailing_test_records(model='mailing.test.optout', count=8)
|
|
|
|
@users('user_marketing')
|
|
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink', 'odoo.addons.mass_mailing.models.mailing')
|
|
def test_mass_mailing_server_batch(self):
|
|
"""Test that the right mail server is chosen to send the mailing.
|
|
|
|
Test also the envelop and the SMTP headers.
|
|
"""
|
|
# Test sending mailing in batch
|
|
mailings = self.env['mailing.mailing'].create([{
|
|
'subject': 'Mailing',
|
|
'body_html': 'Body for <t t-out="object.name" />',
|
|
'email_from': 'specific_user@test.com',
|
|
'mailing_model_id': self.env['ir.model']._get('mailing.test.optout').id,
|
|
}, {
|
|
'subject': 'Mailing',
|
|
'body_html': 'Body for <t t-out="object.name" />',
|
|
'email_from': 'unknown_name@test.com',
|
|
'mailing_model_id': self.env['ir.model']._get('mailing.test.optout').id,
|
|
}])
|
|
with self.mock_smtplib_connection():
|
|
mailings.action_send_mail()
|
|
self.assertEqual(self.find_mail_server_mocked.call_count, 2, 'Must be called only once per mail from')
|
|
|
|
self.assert_email_sent_smtp(
|
|
smtp_from='specific_user@test.com',
|
|
message_from='specific_user@test.com',
|
|
from_filter=self.server_user.from_filter,
|
|
emails_count=8,
|
|
)
|
|
|
|
self.assert_email_sent_smtp(
|
|
# Must use the bounce address here because the mail server
|
|
# is configured for the entire domain "test.com"
|
|
smtp_from=lambda x: 'bounce' in x,
|
|
message_from='unknown_name@test.com',
|
|
from_filter=self.server_domain.from_filter,
|
|
emails_count=8,
|
|
)
|
|
|
|
@users('user_marketing')
|
|
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink', 'odoo.addons.mass_mailing.models.mailing')
|
|
def test_mass_mailing_server_default(self):
|
|
# We do not have a mail server for this address email, so fall back to the
|
|
# "notifications@domain" email.
|
|
mailings = self.env['mailing.mailing'].create([{
|
|
'subject': 'Mailing',
|
|
'body_html': 'Body for <t t-out="object.name" />',
|
|
'email_from': '"Testing" <unknow_email@unknow_domain.com>',
|
|
'mailing_model_id': self.env['ir.model']._get('mailing.test.optout').id,
|
|
}])
|
|
|
|
with self.mock_smtplib_connection():
|
|
mailings.action_send_mail()
|
|
|
|
self.assertEqual(self.find_mail_server_mocked.call_count, 1)
|
|
self.assert_email_sent_smtp(
|
|
smtp_from='notifications@test.com',
|
|
message_from='"Testing" <notifications@test.com>',
|
|
from_filter=self.server_notification.from_filter,
|
|
emails_count=8,
|
|
)
|
|
|
|
self.assertEqual(self.find_mail_server_mocked.call_count, 1, 'Must be called only once')
|
|
|
|
@users('user_marketing')
|
|
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink', 'odoo.addons.mass_mailing.models.mailing')
|
|
def test_mass_mailing_server_forced(self):
|
|
# We force a mail server on one mailing
|
|
mailings = self.env['mailing.mailing'].create([{
|
|
'subject': 'Mailing',
|
|
'body_html': 'Body for <t t-out="object.name" />',
|
|
'email_from': self.server_user.from_filter,
|
|
'mailing_model_id': self.env['ir.model']._get('mailing.test.optout').id,
|
|
}, {
|
|
'subject': 'Mailing',
|
|
'body_html': 'Body for <t t-out="object.name" />',
|
|
'email_from': 'unknow_email@unknow_domain.com',
|
|
'mailing_model_id': self.env['ir.model']._get('mailing.test.optout').id,
|
|
'mail_server_id': self.server_notification.id,
|
|
}])
|
|
with self.mock_smtplib_connection():
|
|
mailings.action_send_mail()
|
|
self.assertEqual(self.find_mail_server_mocked.call_count, 1, 'Must not be called when mail server is forced')
|
|
|
|
self.assert_email_sent_smtp(
|
|
smtp_from='specific_user@test.com',
|
|
message_from='specific_user@test.com',
|
|
from_filter=self.server_user.from_filter,
|
|
emails_count=8,
|
|
)
|
|
|
|
self.assert_email_sent_smtp(
|
|
smtp_from='unknow_email@unknow_domain.com',
|
|
message_from='unknow_email@unknow_domain.com',
|
|
from_filter=self.server_notification.from_filter,
|
|
emails_count=8,
|
|
)
|