Send Devise confirmation emails with Postmark (Rails 6)

Nina P
2 min readMay 19, 2021

--

Here’s a short tutorial for anyone looking to set up Devise confirmation emails on Rails 6.

STEP 0: You should have the Devise gem installed, and :confirmable added to Users.

STEP 1: Sign up for Postmark and go through the account setup process, and get your API key.

postmark signup page

STEP 2: Add the Postmark Rails Gem to your Gemfile and of course remember to run ‘bundle install’ in your terminal. :)

STEP 3: Save your Postmark Server API Token to credentials (Rails 6). You can do it by opening the file with e.g. vim or sublime, whichever you prefer. In your terminal open it with the following command:

EDITOR="sublime — wait" rails credentials:edit

Add your API key there, save the file and close it.

postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

STEP 4: Add the postmark_api_token to your Heroku config. On your terminal:

heroku config:set postmark_api_token=”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

I won’t go into more details on how to set up Rails 6 on Heroku, since there are several instructions for that online.

STEP 5: Add the following settings to /config/environments/development.rb and /config/environments/production.rb , and remember to update the host to your own domain.

config.action_mailer.delivery_method = :postmarkconfig.action_mailer.default_url_options = { host: ‘localhost:3000’} # in production.rb add your domain as the host, e.g. example.comconfig.action_mailer.perform_deliveries = trueconfig.action_mailer.postmark_settings = {
api_token: Rails.application.credentials.postmark_api_token
}

Note that before being able to use Postmark in production, you will first need to verify the domain using a DKIM record (Step 7).

STEP 6: Now you can test this on your rails console, for example:

In case you already have a user created (if not, you can create one), then in rails console on your terminal:

user = User.firstuser.send_confirmation_instructions.deliver

Now you should see an email successfully delivered.

email sent from rails console

You can check it also in Postmark, under servers > activity:

postmark

STEP 7: Go through the Postmark account approval process. And set up DKIM authentication for Postmark.

postmark account review

That’s all for now. If you have any feedback, please let me know in the comments below. Thanks!

--

--

No responses yet