-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Add support for rate limited mailer transports #59985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.4
Are you sure you want to change the base?
Add support for rate limited mailer transports #59985
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Many thanks for the proposal. THis is a nice and useful idea.
I reviewed this PR and it is a good start except the missing tests and a few things I spotted.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
ff86149
to
6d2d7fa
Compare
@@ -14,6 +14,7 @@ CHANGELOG | |||
* Add DSN param `source_ip` to allow binding to a (specific) IPv4 or IPv6 address. | |||
* Add DSN param `require_tls` to enforce use of TLS/STARTTLS | |||
* Add `DkimSignedMessageListener`, `SmimeEncryptedMessageListener`, and `SmimeSignedMessageListener` | |||
* Add support for rate limited transports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be moved to the 7.4 section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be removed
Assume you have to use multiple SMTP servers in your application in order to be able to send emails on behalf of specific email accounts on a variety of hosting providers. Some of these hosting providers may impose limits on how many emails you can send per timeframe - especially in shared hosting environments. For example on Hetzner shared hostings the limit is 500 emails per hour, on webgo 50 emails per hour. Hetzner does not force this limit - but they may disable your account completely, if you break this rule. The same applies to services like sendgrid etc., where you will have certain limits.
Now, if you use
symfony/messenger
in order to send your emails asynchronously, you are able to rate limit the messenger transport:However, this will only rate limit the email queue globally - and not per SMTP server. So if you have to use multiple SMTP servers, where some use different rate limits and others do not need to be rate limited at all, this is not ideal.
Thus this PR introduces support for rate limited mailer transports. The changes are fairly straight forward:
rate_limiter
, just as with messenger transports.Transport
factory, if applicable.AbstractTransport::send()
method - usingensureAccepted()
, so that aRateLimitExceededException
will be thrown.available_at
set to the respective time in the future according to the rate limit.Tests are still missing, as I wanted to hear comments first :)