Skip to content

[17.0][FIX] mail_operating_unit: assign OU mail server before SMTP session grouping#860

Merged
OCA-git-bot merged 1 commit into
OCA:17.0from
jcoux:mail_operating_unit_fix_mail_server_selection
Jun 26, 2026
Merged

[17.0][FIX] mail_operating_unit: assign OU mail server before SMTP session grouping#860
OCA-git-bot merged 1 commit into
OCA:17.0from
jcoux:mail_operating_unit_fix_mail_server_selection

Conversation

@jcoux

@jcoux jcoux commented Jun 24, 2026

Copy link
Copy Markdown

When multiple outgoing mail servers coexist, mail.mail.send() calls
_split_by_mail_configuration() to group mails and open SMTP sessions
before delegating to _send().

At grouping time, mail_server_id is NULL on records whose server is
resolved from an operating unit, so _find_mail_server() picks a server
based on priority and from-filter rules, potentially selecting the wrong
one.

The existing override in _send() writes the correct server to the
database, but by then the SMTP session is already established on the wrong
server.

Extract the OU mail server resolution into a dedicated method
_resolve_operating_unit_mail_server() and call it from a new
_split_by_mail_configuration() override, so mail_server_id is set
before grouping occurs and the SMTP session is opened on the correct server
from the start.

The _send() override is kept as a safety net for direct calls that
bypass _split_by_mail_configuration().

Add test_smtp_server_selection.py which uses MockSmtplibCase to
assert which server is actually passed to connect(), covering both the
OU case (OU server must win over a higher-priority catch-all) and the no-OU
case (standard server selection must still apply).

…ssion grouping

When multiple outgoing mail servers coexist, ``mail.mail.send()`` calls
``_split_by_mail_configuration()`` to group mails and open SMTP sessions
before delegating to ``_send()``.

At grouping time, ``mail_server_id`` is NULL on records whose server is
resolved from an operating unit, so ``_find_mail_server()`` picks a server
based on priority and from-filter rules, potentially selecting the wrong
one.

The existing override in ``_send()`` writes the correct server to the
database, but by then the SMTP session is already established on the wrong
server.

Extract the OU mail server resolution into a dedicated method
``_resolve_operating_unit_mail_server()`` and call it from a new
``_split_by_mail_configuration()`` override, so ``mail_server_id`` is set
before grouping occurs and the SMTP session is opened on the correct server
from the start.

The ``_send()`` override is kept as a safety net for direct calls that
bypass ``_split_by_mail_configuration()``.

Add ``test_smtp_server_selection.py`` which uses ``MockSmtplibCase`` to
assert which server is actually passed to ``connect()``, covering both the
OU case (OU server must win over a higher-priority catch-all) and the no-OU
case (standard server selection must still apply).
@OCA-git-bot OCA-git-bot added mod:mail_operating_unit Module mail_operating_unit series:17.0 labels Jun 24, 2026

@vvrossem vvrossem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jcoux jcoux marked this pull request as ready for review June 24, 2026 12:53

@BhaveshHeliconia BhaveshHeliconia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AaronHForgeFlow

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 17.0-ocabot-merge-pr-860-by-AaronHForgeFlow-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit cdace17 into OCA:17.0 Jun 26, 2026
9 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at a0ba54a. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants