Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Rails Support
      • Working with Bundler
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Java Advanced Topics
      • Working with Spring Boot
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Add-ons
  • All Add-ons
  • Mailtrap by Railsware
Mailtrap by Railsware

This add-on is operated by Railsware Products Studio LLC

Just-in-time email delivery.

Mailtrap by Railsware

Last updated February 24, 2023

Table of Contents

  • Provisioning the add-on
  • Local setup
  • Using with Rails 3.x-6.x
  • Using with Django
  • Tutorials
  • Dashboard
  • Removing the add-on
  • Support

Mailtrap is an Email Delivery Platform that allows customers to manage the email infrastructure in one place. We offer one platform that covers all email-related needs in one place: testing, sending, and in-depth tracking to control how email infrastructure works and performs.

Here, on Heroku, Mailtrap is featured as an add-on for safe and comprehensive email testing. Mailtrap Email Testing is implemented as a dummy SMTP server. It catches all your test emails and displays them in virtual inboxes. With Mailtrap Email Testing, development teams can easily test, view, share transactional and other emails sent from DEVELOPMENT and STAGING environments, without spamming real customers:

  • make sure that email sending script acually works
  • preview and analyze email content (HTML, text, and raw)
  • validate HTML/CSS and get a list of possible errors across popular email clients
  • check whether personalization works as designed and headers are correct (on the advanced plans, you can also test Bcc in emails)
  • make sure that links work properly
  • get spam and domain blocklisting reports
  • automate your email testing workflows
  • forward your test emails to regular recipients and monitor your production server (on the advanced plans)
  • report easily on your progress by sharing your email testing results (on the advanced plans)
  • organize your email testing data with inboxes and projects

Provisioning the add-on

Mailtrap can be attached to a Heroku application via the CLI:

$ heroku addons:create mailtrap
-----> Adding mailtrap to sharp-mountain-4005... done, v18 (free)

Api Token will be available in the app configuration. Using your API token, you can get the credentials used to access the newly provisioned service Mailtrap instance, MAILTRAP_API_TOKEN. This can be done in the following way.

require 'rest-client'
require 'json'

response = RestClient::Resource.new("https://mailtrap.io/api/v1/inboxes.json?api_token=#{ENV['MAILTRAP_API_TOKEN']}").get
first_inbox = JSON.parse(response)[0]

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :user_name => first_inbox['username'],
  :password => first_inbox['password'],
  :address => first_inbox['domain'], :domain => first_inbox['domain'],
  :port => first_inbox['smtp_ports'][0],
  :authentication => :plain
}

For more information, please refer to mailtrap.docs.apiary.io. After installing Mailtrap, the application should be configured to fully integrate with the add-on.

Local setup

After provisioning the add-on, it’s necessary to locally replicate the config vars so your development environment can operate against the service.

Though less portable, it’s also possible to set local environment variables using the export command locally.

Use the Heroku Local command-line tool to configure, run, and manage process types specified in your app’s Procfile. Heroku Local reads configuration variables from a .env file. To view all of your app’s config vars, type heroku config. Use the following command to add the MAILTRAP values ​​retrieved from heroku config to your .env file.

$ 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`.

For more information, see the Heroku Local article.

Using with Rails 3.x-6.x

In config/environments/*.rb specify ActionMailer defaults:

require 'rubygems' if RUBY_VERSION < '1.9'
require 'rest-client'
require 'json'

response = RestClient.get "https://mailtrap.io/api/v1/inboxes.json?api_token=#{ENV['MAILTRAP_API_TOKEN']}"
first_inbox = JSON.parse(response)[0] # get first inbox

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :user_name => first_inbox['username'],
  :password => first_inbox['password'],
  :address => first_inbox['domain'],
  :domain => first_inbox['domain'],
  :port => first_inbox['smtp_ports'][0],
  :authentication => :plain
}

Using with Django

Add the following to settings.py

import requests
response = requests.get("https://mailtrap.io/api/v1/inboxes.json?api_token=<MAILTRAP_API_TOKEN>")
credentials = response.json()[0]

EMAIL_HOST = credentials['domain']
EMAIL_HOST_USER = credentials['username']
EMAIL_HOST_PASSWORD = credentials['password']
EMAIL_PORT = credentials['smtp_ports'][0]
EMAIL_USE_TLS = True

Tutorials

To learn more about developing the email sending functionality and testing it with Mailtrap, read the following tutorials:

  • Sending emails with Ruby
  • Sending emails with Django
  • Sending emails with PHP
  • Sending emails with Node.js
  • Sending emails with Java

Dashboard

The dashboard can be accessed via the CLI:

$ heroku addons:open mailtrap
Opening mailtrap for sharp-mountain-4005…

or by visiting the Heroku Dashboard and selecting the application in question. Select Mailtrap from the Add-ons menu.

Removing the add-on

Mailtrap can be removed via the CLI.

This will not destroy associated data and can be undone!
$ heroku addons:destroy mailtrap
-----> Removing mailtrap from sharp-mountain-4005... done, v20 (free)

Support

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 support@mailtrap.io .

Keep reading

  • All Add-ons

Feedback

Log in to submit feedback.

Ziggeo Marketing & CDP Connect

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences