[17.0][FIX] mail_operating_unit: assign OU mail server before SMTP session grouping#860
Merged
OCA-git-bot merged 1 commit intoJun 26, 2026
Conversation
…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).
yankinmax
approved these changes
Jun 24, 2026
AaronHForgeFlow
approved these changes
Jun 26, 2026
Contributor
|
/ocabot merge patch |
Contributor
|
Hey, thanks for contributing! Proceeding to merge this for you. |
Contributor
|
Congratulations, your PR was merged at a0ba54a. Thanks a lot for contributing to OCA. ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When multiple outgoing mail servers coexist,
mail.mail.send()calls_split_by_mail_configuration()to group mails and open SMTP sessionsbefore delegating to
_send().At grouping time,
mail_server_idis NULL on records whose server isresolved from an operating unit, so
_find_mail_server()picks a serverbased on priority and from-filter rules, potentially selecting the wrong
one.
The existing override in
_send()writes the correct server to thedatabase, 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, somail_server_idis setbefore 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 thatbypass
_split_by_mail_configuration().Add
test_smtp_server_selection.pywhich usesMockSmtplibCasetoassert which server is actually passed to
connect(), covering both theOU case (OU server must win over a higher-priority catch-all) and the no-OU
case (standard server selection must still apply).