Skip to content
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

Handle rate limiting #2

Open
bencroker opened this issue Mar 24, 2024 · 4 comments
Open

Handle rate limiting #2

bencroker opened this issue Mar 24, 2024 · 4 comments

Comments

@bencroker
Copy link

bencroker commented Mar 24, 2024

The MailerSend API enforces daily request quotas and rate limits. I’ve received support requests from people experiencing failed sendouts using the Campaign plugin (putyourlightson/craft-campaign#451, putyourlightson/craft-campaign#462) due to the rate limits.

Have you considered adding handling of 429 - Too many requests errors? I’m not sure whether the desired result would be to avoid such errors completely by building throttling into the plugin, adding a delay on encountering such errors, or simply better handling of the errors, but I’d be interested in hearing your thoughts and whether this is something you have considered.

@janhenckens
Copy link
Member

Haven't run into that myself so far.

I'm using the Symfony adapter, which in turn uses the /v1/email API function https://github.com/symfony/mailer-send-mailer/blob/50f492dc46cac33a86cbb7e061d43220fb3af009/Transport/MailerSendApiTransport.php#L48.

I'm not sure if I could handle these errors from the adapter since the actual sending in done through Craft - apart from implementing the API myself, which I don't want to do at this moment.

@bencroker
Copy link
Author

It looks like you could catch the HttpTransportException and get the status code from the result, to determine whether it is a 429 error.
https://github.com/symfony/mailer-send-mailer/blob/50f492dc46cac33a86cbb7e061d43220fb3af009/Transport/MailerSendApiTransport.php#L60C23-L60C45

@janhenckens
Copy link
Member

Not sure where I could catch that in the plugin as my code isn't doing the sending. I'm only adding the transport but Craft is doing the sending.

Have you done this in another mail adapter @bencroker?

@bencroker
Copy link
Author

bencroker commented Apr 8, 2024

Ok, I see what you mean now. To be able to catch the exceptions, you’d need to define the transport yourself, rather than use MailerSendApiTransport.

Have you done this in another mail adapter @bencroker?

I tend to define mailer transports myself so I can customise the behaviour, although I understand why you wouldn’t want to.

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

No branches or pull requests

2 participants