[12.x] Add first-party support for sending emails with Mailtrap #57999
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.
Hey! This PR proposes a new integration which allows developers to send transactional emails using Mailtrap's PHP library.
The idea behind this feature is that a developer can set these values in their
.envfile:Then the dev will be able to use Mailtrap for sending their emails.
According to their site, Mailtrap has over 150k monthly active users. So I'd like to think there are plenty of Laravel developers in there (or budding Laravel developers) who might be able to make use of this integration 😄
Installation
To use this integration, the official Mailtrap library is required (in a similar way that an extra library is required to use
mailgunas the mailing driver). So it will need to be installed using Composer via the following command:You'll then just need to add your API key and switch the mail driver in the
.envfile like shown above.The integration should now be set up and ready for sending transactional emails.
There are also some new config values (in
config/services.phpandconfig/mail.php) which can be set.Sandbox email testing
One of the really cool things I like about Mailtrap (and have been using for a few years myself) is the sandbox feature which captures emails you send from your app so you can preview them, rather than sending them to the intended recipient.
Usually, I'd need to configure my
.envfile with the correct SMTP credentials for sandbox testing. But for with these changes, I'd just need to set theMAILTRAP_SANDBOX_ENABLEDtotrueand theMAILTRAP_INBOX_IDto the ID of my sandbox inbox ID like so:So I think it's pretty cool that we can toggle the sandbox testing with just a single boolean in the environment 😄
Further PRs
If this PR is merged, I'd love to make some more PRs to the application skeleton repo to add the config fields (
config/mail.phpandconfig/services.php).I'm also more than happy to make any necessary PRs to the docs.
Testing
I wasn't sure how to write automated tests for this, sorry. But I've manually tested different scenarios to check that the emails can be sent.
You may already have a Mailtrap account yourself. But just in case you don't, I'll email you (Taylor) some API credentials that I've set up on my Mailtrap account so you can test sending emails. I thought this would be useful so you don't have to start configuring DNS records and waiting for domain approval, etc.
Hopefully, this is something which you think is useful. Please give me a shout if you'd like anything changed at all 😄