Skip to content

[Fix] Mail #0048326: Send and delete scheduled mails as mailbox owner - #12067

Merged
mjansenDatabay merged 6 commits into
ILIAS-eLearning:release_11from
fhelfer:mail/mantis/48326-scheduled-mails
Sep 18, 2026
Merged

mjansenDatabay merged 6 commits into
ILIAS-eLearning:release_11from
fhelfer:mail/mantis/48326-scheduled-mails

Conversation

@fhelfer

@fhelfer fhelfer commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Fixes Mantis #48326: scheduled outbox mails were sent again every night and never removed from the outbox.

Root cause: ScheduledMailsCron used a single ilMail / ilFormatMail instance bound to the cron actor ($DIC->user()). After sending, deleteMails() executed:

DELETE FROM mail WHERE user_id = <cron_user_id> AND mail_id = <outbox_id>

Outbox rows belong to the scheduling user, so the DELETE matched 0 rows (no error, cron status OK). The same rows were picked up on every run.
Additionally, send/enqueue ran as the cron user instead of the mailbox owner (wrong sender, wrong attachment file pool, wrong SMTP permission checks).

Changes

  • Load mail.user_id in OutboxDatabaseRepository and expose it on MailDeliveryData
  • For each due scheduled mail, create ilFormatMail($owner_id) and ilMail($owner_id)
  • Remove outbox entry only after successful enqueue() for that mail (not in finally, not batched with wrong user)
  • Log non-empty validation errors returned by enqueue()
  • Continue processing remaining mails when one mail fails (instead of aborting the whole cron run)

ScheduledMailsCron used the cron actor for enqueue() and deleteMails(),
so outbox rows were never removed (DELETE matched user_id of cron user).
Per mail, use the outbox owner's ilFormatMail/ilMail instance, delete only
after successful send, and log enqueue validation errors.
@fhelfer fhelfer added bugfix php Pull requests that update Php code labels Sep 15, 2026
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Keep cron status OK when individual mails fail, summarize problems in the
result message (max 400 chars), cache ilFormatMail/ilMail per owner, remove
unnecessary withContextId call, and delete orphan outbox rows without owner.
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Comment thread components/ILIAS/Mail/classes/Folder/OutboxDatabaseRepository.php Outdated
Comment thread components/ILIAS/Mail/classes/MailDeliveryData.php Outdated
Move outbox deletion into OutboxRepository, use structured logger
placeholders with short cron summaries, cast mail_id/user_id directly,
and make MailDeliveryData user_id a non-nullable int defaulting to 0.
Comment thread components/ILIAS/Mail/src/Cron/ScheduledMailsCron.php Outdated
Comment thread components/ILIAS/Mail/classes/Folder/OutboxDatabaseRepository.php Outdated
Delete sent scheduled mails via the cached ilFormatMail instance and remove
orphan outbox rows without a valid user including mail_attachment cleanup.
Comment thread components/ILIAS/Mail/classes/Folder/OutboxDatabaseRepository.php Outdated
Comment thread components/ILIAS/Mail/classes/Folder/OutboxDatabaseRepository.php
Comment thread components/ILIAS/Mail/classes/Message/MailRecordMapper.php

@mjansenDatabay mjansenDatabay 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.

Hi @fhelfer ,

IMO the PR looks good now, except for one thing: We should still try to delete sent mail records which hold an existing owner (with the corresponding $mailer instance).

Best regards,
Michael

@mjansenDatabay
mjansenDatabay merged commit 46fe419 into ILIAS-eLearning:release_11 Sep 18, 2026
4 checks passed
mjansenDatabay pushed a commit that referenced this pull request Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants