Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
To send emails via sendingblue, I used Mime Email class with sendingBlue bridge,
I noticed an Exception while trying to send the email to a remote template hosted on sending blue;
Sendingblue/brevo expects to receive a
templateId
header to select the template to be used for this email, that is supposed to be enough;I encountered a LogicException because an Email should always have body or an attachment,
The source of this exception comes from
Email::ensureBodyValid()
private method.A simple solution for this issue, is to define an arbitrary body (I usually send the templateId as body text), so no big deal.
I do not consider this to be a bug, not a serious one at least.
That gave me the idea to make a pull request, to define a special type for Remote email, with I called
RemoteEmail
in the Mime component for emails hosted on the cloud, which allows the email to have an empty body, instead it will define two things, a templateId, the header name to be sent the email api,I had to change the visibility of the class
Email::ensureBodyValid()
to protected instead of private, to be able to customize it's behaviour.I included tests for
RemoteEmail
class in the Mime component, and Tests to integrate it with SendingBlueBridge, but I did not integration bridge tests to avoid unit tests issues in the Mailer component since the RemoteEmail class would not be recognised,Sending Blue Test file in another branch:
https://github.com/mmouih/symfony/blob/be08c7ca6bdf44ac148f09761cdd0b9e8c755190/src/Symfony/Component/Mailer/Bridge/Sendinblue/Tests/Transport/SendinblueApiTransportRemoteEmailTest.php
Example of a failure test:
symfony/src/Symfony/Component/Mime/Tests/RemoteEmailTest.php
Lines 30 to 42 in 75157ca
A success example below:
symfony/src/Symfony/Component/Mime/Tests/RemoteEmailTest.php
Lines 44 to 57 in 75157ca
This RemoteEmail class is a subtitute to Email on most usages, however the body is always Empty.