In this post, we’ll go over two ways you can send Laravel emails via Postmark. We’ll explore the nuts and bolts of setting up the Postmark adapter for Laravel written by Craig Paul, and we’ll also look at how you can send email via SMTP. But first, let’s walk through signing up for a free Postmark developer account.
Create a Postmark account and sender signature #
If you already have a Postmark account, you can skip this step. If you don’t have an account, head to the homepage and click “Start Free Trial” in the top right corner. Fill out your account details then click “Let’s get started.”
Once you’ve entered your account information, you’ll be asked to create and confirm a sender signature. This step is necessary to send email from Postmark.
Note: Postmark developer accounts are limited to 100 emails per month. Before you can send more than that, you’ll need to go through the account approval process. To maintain high deliverability rates, Postmark is selective about the types of emails that can be sent.
Set up the Postmark adapter for Laravel #
In the following code examples, I’ll assume that you have a fresh new Laravel project using Laravel 5.7 and that you’re using a Mac. Let’s set up the Laravel Postmark adapter.
1. Open terminal and cd to your new Laravel project directory
2. Now run
composer require coconutcraig/laravel-postmark:
Open up your
config/services.php and add:
return [ // ... 'postmark' => [ 'token' => env('POSTMARK_TOKEN'), ], ];
POSTMARK_TOKEN, you’ll add the actual secret to your ENV file next.
4. Open your
POSTMARK_TOKEN=<YOUR-SERVER-API-TOKEN-HERE> to the bottom of the file and be sure to replace
<YOUR-SERVER-API-TOKEN-HERE> with your Server API token, which you can find in your Postmark dashboard in the API Token section.
Now whenever you send email through your Laravel app, it will be sent via your Postmark account.
Note: If you’re running an older version of Laravel, you can check out and use an older branch of this adapter:
Send email via SMTP #
Now let’s look at what it takes to send email via SMTP through Postmark instead of through the Postmark API.
1. Log into your Postmark dashboard, and head to the SMTP tab within the “Setup Instructions” section:
2. Next, open up
config/mail.php in your favorite text editor.
Change the global from name and address to match the sender signature you set up during the Postmark account creation process above. If you have an existing Postmark account and skipped the account creation step above, you can find your sender signature by clicking “Sender Signatures” from your Postmark dashboard.
Finally, change the
MAIL_PASSWORD to match the username and password listed in your setup instructions:
A couple of notes:
- Yes, the username and password are intentionally the same. 😉
- You can ignore the sendmail driver path as this sends through SMTP, not sendmail.
- Additional ports and authentication protocols are listed in your setup instructions (in the black box above), but if you don’t know what you’re doing, it’s best to leave them defaulted to port
tlsfor the protocol.
Big props to Craig Paul for open sourcing his Postmark adapter for Laravel.