Registry Mirror
Skip to content

Conversation

@grandnode-dev

@grandnode-dev grandnode-dev commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Type: bugfix

Issue

The "Send emails" task runs every minute, takes up to 500 queued e-mails and gives each one three tries (maxTries = 3) with no pause between them. A fast-failing SMTP outage of about three minutes (refused connection, DNS failure, provider maintenance) used up every try, and the e-mails were abandoned: order confirmations, password recovery links, everything. Recovery was manual (Admin → Queued emails → Requeue, one by one).

Solution

A failed try now postpones the next one through the existing QueuedEmail.DontSendBeforeDateUtc, which SearchEmails(loadOnlyItemsToBeSent: true) already honours. The pauses come from a new appsettings section, in all four hosts:

"QueuedEmail": {
  "RetryDelayMinutes": [ 1, 5, 15, 30, 60, 120 ]
}
Failed try Next try not before (default)
1 +1 min
2 +5 min
3 +15 min
4 +30 min
5 +60 min
6 +120 min
7 none, the e-mail is abandoned
  • The try limit follows from the list: one try more than there are pauses. The default is 7 tries over about four hours. A missing or empty list uses the default, which lives in the task, so installations with their own appsettings keep working. A value of 0 retries on the next run.
  • QueuedEmailConfig is bound like the other config sections (StartupBase) and injected into the task, the same way AuditLogRetentionScheduleTask gets AuditConfig. The property has no initializer on purpose: the configuration binder would otherwise mix the defaults with the configured values.
  • A successful send leaves DontSendBeforeDateUtc as it was. The last failed try does not set it, because no try is left. A negative try count (from a direct database edit) is counted without a pause instead of throwing and stopping the run.
  • A run stopped mid-send still does not count as a try, and the e-mail is not postponed.
  • There is no new field and no migration. E-mails already in the queue with 3 to 6 failed tries get more tries on the next run.
  • An admin can still force an immediate send with "Send immediately" on the queued e-mail, which clears the date.

Out of scope: telling transient SMTP errors apart from permanent ones. A permanently failing e-mail now uses up its tries over about four hours instead of 3 minutes.

Breaking changes

None. The Admin queued e-mail list defaults to "max sent tries 10", so e-mails abandoned after 7 tries still show in the list.

Testing

  1. Unit tests: dotnet test src/Tests/Grand.Modules.Tests --filter QueuedMessagesSendScheduleTaskTests. They check:
    • the pause after each failed try and that the last failed try is not postponed;
    • that a successful send leaves the date alone;
    • the try limit passed to the query;
    • delays from config, the empty list falling back to the defaults, and a negative try count.
  2. Manual:
    1. Set the default e-mail account's SMTP host to an unreachable one, for example localhost on port 1.
    2. Trigger any e-mail, for example a password recovery.
    3. After the next "Send emails" run, open Admin → System → Queued emails. The e-mail shows Sent tries 1 and "Don't send before" about 1 minute ahead. The run after that shows 2 tries and about 5 minutes ahead.
    4. Optionally set QueuedEmail:RetryDelayMinutes to [ 2 ], restart, and check that a new failing e-mail waits 2 minutes and is abandoned after its second try.
    5. Restore the SMTP settings. The e-mail goes out on the first run after its "Don't send before" time.

The "Send emails" task runs every minute and gave each e-mail three tries
with no pause between them, so an SMTP outage of about three minutes
abandoned every queued e-mail, order confirmations included, until someone
requeued them by hand.

A failed try now sets DontSendBeforeDateUtc to 1, 5, 15, 30, 60 and then
120 minutes ahead, and an e-mail gets seven tries, which covers almost four
hours of outage. The field and its filter already exist, so no migration is
needed. A run stopped mid-send still does not count as a try.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 15:17

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The pauses between tries of a failed e-mail move to the new "QueuedEmail"
section (RetryDelayMinutes), so an installation can cover a longer or a
shorter SMTP outage without a code change. The try limit still follows
from the list: one try more than there are pauses. A missing or empty
list keeps the default of 1, 5, 15, 30, 60 and 120 minutes.

A negative try count no longer indexes the list, which would have thrown
from the catch block and stopped the run for every e-mail after it.
@grandnode-dev
grandnode-dev merged commit 44b4ed8 into develop Dec 2, 2026
9 checks passed
@grandnode-dev
grandnode-dev deleted the fix/queued-email-retry-backoff branch December 2, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants