-
Notifications
You must be signed in to change notification settings - Fork 9
mailtrap
Mailtrap is an add-on for providing safe email delivery testing.
Mailtrap is a dummy SMTP server for development teams to test, view, share transactional and other emails sent from DEVELOPMENT and STAGING environments, without spamming real customers
Mailtrap can be attached to a Heroku application via the CLI:
:::term
$ heroku addons:add mailtrap
-----> Adding mailtrap to sharp-mountain-4005... done, v18 (free)
MAILTRAP_HOST
, MAILTRAP_PORT
, MAILTRAP_USER_NAME
, MAILTRAP_PASSWORD
settings will be available in the app configuration and will contain the credentionals used to access the newly provisioned Mailtrap service instance. This can be confirmed using the heroku config
command.
:::term
$ heroku config -s | grep MAILTRAP
MAILTRAP_HOST=mailtrap.io
MAILTRAP_PORT=2525
MAILTRAP_USER_NAME=user
MAILTRAP_PASSWORD=pass
After installing Mailtrap the application should be configured to fully integrate with the add-on.
After provisioning the add-on it’s necessary to locally replicate the config vars so your development environment can operate against the service.
Use Foreman to configure, run and manage process types specified in your app’s Procfile. Foreman reads configuration variables from an .env file. Use the following command to add the MAILTRAP values retrieved from heroku config to .env
.
:::term
$ heroku config -s | grep MAILTRAP >> .env
$ more .env
Credentials and other sensitive configuration values should not be committed to source-control. In Git exclude the .env file with: `echo .env >> .gitignore`.
In config/environments/*.rb specify ActionMailer defaults:
:::ruby
if ENV['MAILTRAP_HOST'].present?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:user_name => ENV['MAILTRAP_USER_NAME'],
:password => ENV['MAILTRAP_PASSWORD'],
:address => ENV['MAILTRAP_HOST'],
:port => ENV['MAILTRAP_PORT'],
:authentication => :plain
}
end
Add the following to settings.py
:::python
EMAIL_HOST = ENV['MAILTRAP_HOST']
EMAIL_HOST_USER = ENV['MAILTRAP_USER_NAME']
EMAIL_HOST_PASSWORD = ENV['MAILTRAP_PASSWORD']
EMAIL_PORT = ENV['MAILTRAP_PORT']
EMAIL_USE_TLS = False
The dashboard can be accessed via the CLI:
:::term
$ heroku addons:open mailtrap
Opening mailtrap for sharp-mountain-4005…
or by visiting the Heroku apps web interface and selecting the application in question. Select Mailtrap from the Add-ons menu.
Mailtrap can be removed via the CLI.
:::term
$ heroku addons:remove mailtrap
-----> Removing mailtrap from sharp-mountain-4005... done, v20 (free)
All Mailtrap support and runtime issues should be submitted via on of the Heroku Support channels. Any non-support related issues or product feedback is welcome at [email protected].