Skip to content

Add delay when queuing multiple debt email#1300

Merged
beesaferoot merged 7 commits intomainfrom
add-delay-sending-debt-mail
Feb 23, 2026
Merged

Add delay when queuing multiple debt email#1300
beesaferoot merged 7 commits intomainfrom
add-delay-sending-debt-mail

Conversation

@beesaferoot
Copy link
Copy Markdown
Contributor

Closes #1299

Brief summary of the change made

Are there any other side effects of this change that we should be aware of?

Describe how you tested your changes?

Pull Request checklist

Please confirm you have completed any of the necessary steps below.

  • Meaningful Pull Request title and description
  • Changes tested as described above
  • Added appropriate documentation for the change.
  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@beesaferoot beesaferoot requested a review from dmohns February 9, 2026 13:56
@dmohns
Copy link
Copy Markdown
Member

dmohns commented Feb 10, 2026

Hey @beesaferoot

Two comments here

  1. How do you know the error is rate limit related? I'm reading the Gmail SMTP relay docs It looks like we should be really far from any limit
    image

    Also, I would have expected a rate limit error: https://support.google.com/a/answer/6140680?sjid=6095609842808687166-EU Did we see any of these?

  2. Regarding the actual implementation. Can't we just use a queue-based Rate Limit? https://laravel.com/docs/12.x/queues#rate-limiting instead of a custom delay implementation? We could even go further and at exponential backoff retries on queue level.

@beesaferoot
Copy link
Copy Markdown
Contributor Author

  1. How do you know the error is rate limit related? I'm reading the Gmail SMTP relay docs It looks like we should be really far from any limit

This link (https://support.google.com/a/answer/3221692) was part of the error message, I did a little search on the cause of issues like this. I came across this (https://forum.mautic.org/t/error-sending-emails/25498/2), also asked ChatGPT.

I know our IP isn't banned entirely because we still successfully send out emails in other cases (i.e., welcome email etc), but there appears to always be an error when trying to send out debt emails. What do you suggest? without making uninformed guess, I'm not sure what to make of it yet.

Regarding the actual implementation. Can't we just use a queue-based Rate Limit? https://laravel.com/docs/12.x/queues#rate-limiting instead of a custom delay implementation? We could even go further and at exponential backoff retries on queue level.

This is a better solution. I will look into it. Thank you

@dmohns
Copy link
Copy Markdown
Member

dmohns commented Feb 10, 2026

  1. How do you know the error is rate limit related? I'm reading the Gmail SMTP relay docs It looks like we should be really far from any limit

This link (https://support.google.com/a/answer/3221692) was part of the error message, I did a little search on the cause of issues like this. I came across this (https://forum.mautic.org/t/error-sending-emails/25498/2), also asked ChatGPT.

I know our IP isn't banned entirely because we still successfully send out emails in other cases (i.e., welcome email etc), but there appears to always be an error when trying to send out debt emails. What do you suggest? without making uninformed guess, I'm not sure what to make of it yet.

Yeah, this is really tricky to understand. I'm just curious because they provide such a detailed list of SMTP Error codes: https://support.google.com/a/answer/3726730?sjid=16209648178720520903-EU

For example

550 5.7.1 This email has been rate limited.

Interestingly, the error already gives us some indication. Try again later, 😂 Are we retrying email sending?

Regarding the actual implementation. Can't we just use a queue-based Rate Limit? https://laravel.com/docs/12.x/queues#rate-limiting instead of a custom delay implementation? We could even go further and at exponential backoff retries on queue level.

This is a better solution. I will look into it. Thank you

👍

@beesaferoot
Copy link
Copy Markdown
Contributor Author

Interestingly, the error already gives us some indication. Try again later, 😂 Are we retrying email sending?

Yes but it doesn't have any backoff logic; it simply retries immediately

@beesaferoot beesaferoot force-pushed the add-delay-sending-debt-mail branch from 5b11f1a to ebd6933 Compare February 10, 2026 15:18
Comment thread src/backend/app/Services/ExportServices/OutstandingDebtsExportService.php Outdated
@beesaferoot beesaferoot force-pushed the add-delay-sending-debt-mail branch from 1e16a98 to ff3867c Compare February 10, 2026 16:03
@beesaferoot beesaferoot requested a review from dmohns February 11, 2026 11:13
* @return array<int, RateLimited|ThrottlesExceptions>
*/
public function middleware(): array {
return [(new RateLimited('emails'))->releaseAfter(3),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

releaseAfter(3) seems wrong here 🤔 Below we are using releaseAfter(5 * 60). Should they be different or should they be the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

5 minutes is for Throttle middleware which happens only after exceeding maximum attempts. 3 seconds is meant for a delay on each attempt.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Essentially, my question is, why are the values different between HtmlEmail.php and PlainEmail.php? I would have expected them to be the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are correct, that's not expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now updated.

@beesaferoot beesaferoot merged commit 02d9b9d into main Feb 23, 2026
16 checks passed
@beesaferoot beesaferoot deleted the add-delay-sending-debt-mail branch February 23, 2026 09:32
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.

[Bug]: Ratelimited by Google STMP server when using multiple outstanding debts email

2 participants