This add-on is operated by Sidebored.io,Inc.
Send email from your Heroku Apps.
Mailer To Go
Last updated July 11, 2023
Table of Contents
Mailer To Go provides a simple, secure, and scalable email delivery service. Use Mailer To Go to send emails from your Heroku app using your email addresses and domains. There’s no need to maintain complex email systems or learn any new APIs or programming libraries.
Provision the Add-on
Attach Mailer To Go to a Heroku application via the CLI:
See a list of all plans available here.
$ heroku addons:create mailertogo
-----> Adding mailertogo to spring-roll-app-3207... done, v25 (free)
After you provision Mailer To Go, add your custom domain in order to send email from your email address.
Once you add and verify your domain, the MAILERTOGO_SMTP_HOST
, MAILERTOGO_SMTP_PORT
, MAILERTOGO_SMTP_USER
and MAILERTOGO_SMTP_PASSWORD
config variables are available in your app’s configuration. It contains the details of your provisioned SMTP endpoint host, port, user and password. You can see the config variables via the heroku config
command:
$ heroku config | grep MAILERTOGO
You can also attach your Mailer To Go add-on to another Heroku app using the following command:
heroku addons:attach mailertogo-greytuna-21562 -a sashimi-app-7242
-----> Attaching mailertogo-greytuna-21562 to sashimi-app-7242.. done, v19 (free)
Local Setup
Environment Setup
After you provision the add-on, it’s necessary to locally replicate its config vars so your development environment can operate against the service.
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 for each value that you want to add to your .env
file:
$ heroku config:get MAILERTOGO_SMTP_USER -s >> .env
$ heroku config:get MAILERTOGO_SMTP_PASSWORD -s >> .env
$ heroku config:get MAILERTOGO_SMTP_HOST -s >> .env
$ heroku config:get MAILERTOGO_SMTP_PORT -s >> .env
$ heroku config:get MAILERTOGO_DOMAIN -s >> .env
Don’t commit credentials and other sensitive configuration values to source-control. In Git exclude the .env
file with: echo .env >> .gitignore
.
For more information, see the Heroku Local article.
Dashboard
Use The Mailer To Go dashboard to:
- Get access information to your email server (user, password, host, and port).
- Rotate your password. This action generates a new password and changes the value of the
MAILERTOGO_SMTP_PASSWORD
config var.
It’s recommended to rotate passwords every 90 days.
- Add, remove, and set default domains. See Set Up Domains.
- Get usage metrics to monitor your add-on usage.
You can access the dashboard via the CLI:
$ heroku addons:open mailertogo
Opening mailertogo for spring-roll-app-3207
or by visiting the Heroku Dashboard and selecting the application in question. Select Mailer To Go from the Add-ons menu.
Set Up Domains
Use domains to send emails from your own domains and improve your email delivery rates.
Mailer To Go has endpoints in multiple regions for the sake of privacy, compliance and high availability. You must add the same domain for each one of the regions from which you’d like to send emails.
Domain names are case-insensitive. If you verify yourdomain.com, you can also send from YOURDOMAIN.com.
To add a domain:
- Click Add domain.
- Select the region to associate the domain with.
- Click Add domain. The domain shows up in the domains list.
You can send from any subdomains, and/or email addresses of that domain without specifically verifying any subdomain.
The new domain record shows up with the DNS records required to verify your domain.
Verify Your Domain
Mailer To Go requires that you verify your domain before you can send emails using it. This security measure is required in order to confirm that you own the domain and protects your email reputation by ensuring others can’t use your domain without permission.
If you verify a domain with Mailer To Go, you can send from any subdomains, and/or email addresses of that domain without specifically verifying any subdomain.
Verifying your domain also removes the via amazonses.com
tag in some email clients, such as Gmail or Outlook.
Mailer To Go uses the DKIM (DomainKeys Identified Mail) standard to cryptographically sign the messages sent on your behalf. Email providers then use these signatures to verify these signatures against the DNS records you set up for your domain.
Each domain has a unique set of DNS records that you must add to the DNS settings for your domain.
Mailer To Go checks for DNS changes every few minutes and automatically reflects your changes. You can click Refresh status to manually refresh their state.
After the verification process is complete, the domain state is Verified
and you can send emails using your domain.
DNS record propagation can take up to 72 hours, but usually takes a few minutes.
Here are some links to the documentation for editing DNS records with popular domain providers. If your DNS provider isn’t listed here, log in to your provider’s site and search their help documents on adding DNS records.
DNS Provider | Documentation |
---|---|
AWS Route53 | Supported DNS record types |
Cloudflare | Managing DNS records in Cloudflare |
Digital Ocean | How to Create, Edit, and Delete DNS Records |
Dreamhost | Adding custom DNS records |
DNSimple | Managing CNAME Records |
GoDaddy | Add a CNAME record |
Google Domains | DNS basics |
Kinsta DNS | How to Add DNS Records |
HostGator | Manage DNS Records with HostGator/eNom |
Namecheap | How to create CNAME record for your domain |
Names.co.uk | Changing your domain’s DNS settings |
Wordpress | Adding Custom DNS Records |
Wix | Adding or Updating CNAME Records |
Default Domain
You can set a domain as your default domain. Whenever you set or update a default domain, it automatically updates the MAILERTOGO_HOST
, MAILERTOGO_PASSWORD
and MAILERTOGO_DOMAIN
config vars with your Mailer To Go SMTP endpoint details and your default domain name.
Send Emails with SMTP
Mailer To Go sends email using SMTP, which is the most common email protocol on the internet. You can use a variety of SMTP-enabled programming languages and software to connect to the Mailer To Go SMTP endpoint.
Your SMTP user, password, host, and port are available for each domain.
Using with Ruby
You can use Mailer To Go with any Ruby email client.
Here’s a sample configuration for ActionMailer and Ruby on Rails:
mailertogo_host = ENV.fetch("MAILERTOGO_SMTP_HOST")
mailertogo_port = ENV.fetch("MAILERTOGO_SMTP_PORT", 587)
mailertogo_user = ENV.fetch("MAILERTOGO_SMTP_USER")
mailertogo_password = ENV.fetch("MAILERTOGO_SMTP_PASSWORD")
mailertogo_domain = ENV.fetch("MAILERTOGO_DOMAIN", "mydomain.com")
config.action_mailer.smtp_settings = {
:address => mailertogo_host,
:port => mailertogo_port,
:user_name => mailertogo_user,
:password => mailertogo_password,
:domain => mailertogo_domain,
:authentication => :plain,
:enable_starttls_auto => true,
}
To send an email message with Pony:
mailertogo_host = ENV.fetch("MAILERTOGO_SMTP_HOST")
mailertogo_port = ENV.fetch("MAILERTOGO_SMTP_PORT", 587)
mailertogo_user = ENV.fetch("MAILERTOGO_SMTP_USER")
mailertogo_password = ENV.fetch("MAILERTOGO_SMTP_PASSWORD")
mailertogo_domain = ENV.fetch("MAILERTOGO_DOMAIN", "mydomain.com")
Pony.mail({
:to => 'you@example.com',
:via => :smtp,
:via_options => {
:address => mailertogo_host,
:port => mailertogo_port,
:user_name => mailertogo_user,
:password => mailertogo_password,
:domain => mailertogo_domain,
:authentication => :plain,
:enable_starttls_auto => true,
},
})
Using with Python
The smtplib can be used to send mail using SMTP.
Here’s some sample code that demonstrates how to send mail via Mailer To Go with Python:
from os import environ
import smtplib
import email.utils
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# read MailerToGo env vars
mailertogo_host = environ.get('MAILERTOGO_SMTP_HOST')
mailertogo_port = environ.get('MAILERTOGO_SMTP_PORT', 587)
mailertogo_user = environ.get('MAILERTOGO_SMTP_USER')
mailertogo_password = environ.get('MAILERTOGO_SMTP_PASSWORD')
mailertogo_domain = environ.get('MAILERTOGO_DOMAIN', "mydomain.com")
# sender
sender_user = 'noreply'
sender_email = "@".join([sender_user, mailertogo_domain])
sender_name = 'Example'
# recipient
recipient_email = sender_email # change to recipient email. Make sure to use a real email address in your tests to avoid hard bounces and protect your reputation as a sender.
recipient_name = 'Ms. Example'
# subject
subject = 'Mailer To Go Test'
# text body
body_plain = ("Hi,\n"
"Test from Mailer To Go 😊\n"
)
# html body
line_break = '\n' #used to replace line breaks with html breaks
body_html = f'''<html>
<head></head>
<body>
{'<br/>'.join(body_plain.split(line_break))}
</body>
</html>'''
# create message container
message = MIMEMultipart('alternative')
message['Subject'] = subject
message['From'] = email.utils.formataddr((sender_name, sender_email))
message['To'] = email.utils.formataddr((recipient_name, recipient_email))
# prepare plain and html message parts
part1 = MIMEText(body_plain, 'plain')
part2 = MIMEText(body_html, 'html')
# attach parts to message
message.attach(part1)
message.attach(part2)
# send the message.
try:
server = smtplib.SMTP(mailertogo_host, mailertogo_port)
server.ehlo()
server.starttls()
server.ehlo()
server.login(mailertogo_user, mailertogo_password)
server.sendmail(sender_email, recipient_email, message.as_string())
server.close()
except Exception as e:
print ("Error: ", e)
else:
print ("Email sent!")
Using with Node.js
You can use Mailer To Go with any Node.js email client.
Here’s a complete example to send an email with Nodemailer:
"use strict";
const nodemailer = require("nodemailer");
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// Get Mailer To Go SMTP connection details
let mailertogo_host = process.env.MAILERTOGO_SMTP_HOST;
let mailertogo_port = process.env.MAILERTOGO_SMTP_PORT || 587;
let mailertogo_user = process.env.MAILERTOGO_SMTP_USER;
let mailertogo_password = process.env.MAILERTOGO_SMTP_PASSWORD;
let mailertogo_domain = process.env.MAILERTOGO_DOMAIN || "mydomain.com";
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: mailertogo_host,
port: mailertogo_port,
requireTLS: true, // Must use STARTTLS
auth: {
user: mailertogo_user,
pass: mailertogo_password,
},
});
// Sender domain must match mailertogo_domain or otherwise email will not be sent
let from = `"Sender Name" <noreply@${mailertogo_domain}>`;
// Change to recipient email. Make sure to use a real email address in your tests to avoid hard bounces and protect your reputation as a sender.
let to = `"Recipient Name" <noreply@${mailertogo_domain}>`;
let subject = "Mailer To Go Test";
// Send mail with defined transport object
let info = await transporter.sendMail({
from: from, // Sender address, must use the Mailer To Go domain
to: to, // Recipients
subject: subject, // Subject line
text: "Test from Mailer To Go 😊.", // Plain text body
html: "Test from <b>Mailer To Go</b> 😊.", // HTML body
});
console.log("Message sent: %s", info.messageId);
}
main().catch(console.error);
Using with Go
You can use Mailer To Go with any Go email client.
Here’s a complete example to send an email with Gomail. It requires Go 1.2 or newer. With Go 1.5, no external dependencies are used.
package main
import (
"log"
"net/http"
"os"
"strconv"
"strings"
"github.com/gin-gonic/gin"
_ "github.com/heroku/x/hmetrics/onload"
gomail "gopkg.in/mail.v2"
)
func sendEmail(sender string, recipients []string, subject string, message string) error {
var mailerToGoHost = os.Getenv("MAILERTOGO_SMTP_HOST")
var mailerToGoPort, _ = strconv.ParseInt(os.Getenv("MAILERTOGO_SMTP_PORT"), 10, 64)
var mailerToGoUser = os.Getenv("MAILERTOGO_SMTP_USER")
var mailerToGoPassword = os.Getenv("MAILERTOGO_SMTP_PASSWORD")
var mailerToGoDomain = os.Getenv("MAILERTOGO_DOMAIN")
smtp_message := gomail.NewMessage()
// Set headers.
smtp_message.SetHeader("From", sender+"@"+mailerToGoDomain)
smtp_message.SetHeader("To", strings.Join(recipients[:], ","))
smtp_message.SetHeader("Subject", subject)
// Set html body.
smtp_message.SetBody("text/html", message)
// Connect to SMTP server.
smtp_dialer := gomail.NewDialer(mailerToGoHost, int(mailerToGoPort), mailerToGoUser, mailerToGoPassword)
// Send EMail.
err := smtp_dialer.DialAndSend(smtp_message)
return err
}
func main() {
port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
}
router := gin.New()
router.Use(gin.Logger())
router.LoadHTMLGlob("templates/*.tmpl.html")
router.Static("/static", "static")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl.html", nil)
})
var mailerToGoDomain = os.Getenv("MAILERTOGO_DOMAIN")
var message = "The Server is Starting... "
err := sendEmail("server", []string{"admins@"+mailerToGoDomain}, "Server", message)
if err != nil {
log.Fatal(err)
}
router.Run(":" + port)
}
Using with PHP
You can use Mailer To Go with any PHP email client.
Here’s a complete example to send an email with PHPMailer.
<?php
require("vendor/autoload.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Passing true enables exceptions.
$phpmailer = new PHPMailer(true);
try {
// Configure SMTP
$phpmailer->isSMTP();
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
// ENV Credentials
$phpmailer->Host = getenv("MAILERTOGO_SMTP_HOST", true);
$phpmailer->Port = intval(getenv("MAILERTOGO_SMTP_PORT", true));
$phpmailer->Username = getenv("MAILERTOGO_SMTP_USER", true);
$phpmailer->Password = getenv("MAILERTOGO_SMTP_PASSWORD", true);
$mailertogo_domain = getenv("MAILERTOGO_DOMAIN", true);
// Mail Headers
$phpmailer->setFrom("mailer@{$mailertogo_domain}", "Mailer");
// Change to recipient email. Make sure to use a real email address in your tests to avoid hard bounces and protect your reputation as a sender.
$phpmailer->addAddress("noreply@{$mailertogo_domain}", "Recipient");
// Message
$phpmailer->isHTML(true);
$phpmailer->Subject = "Mailer To Go Test";
$phpmailer->Body = "<b>Hi</b>\nTest from Mailer To Go 😊\n";
$phpmailer->AltBody = "Hi!\nTest from Mailer To Go 😊\n";
// Send the Email
$phpmailer->send();
echo "Message has been sent";
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$phpmailer->ErrorInfo}";
}
Migrating Between Plans
Carefully manage the migration timing to ensure proper application function during the migration process.
Use the heroku addons:upgrade
command to migrate to a new plan.
$ heroku addons:upgrade mailertogo:newplan
-----> Upgrading mailertogo:[[newplan]] to spring-roll-app-3207... done, v26 ($50/mo)
Your plan has been updated to: mailertogo:newplan
Removing the Add-on
You can remove Mailer To Go via the CLI:
This action destroys all associated data and can’t be undone!
$ heroku addons:destroy mailertogo
-----> Removing mailertogo from spring-roll-app-3207... done, v19 (free)
Security
- The data you send on Mailer To Go is encrypted in transit.
- Mailer To Go’s physical infrastructure is hosted on Amazon Web Services’ (AWS) data centers.
- AWS Security Groups (virtual firewalls) restrict access to Mailer To Go’s network from external networks, and between systems internally.
- Only Crazy Ant Labs staff have back-end access to the OS level and AWS console. This access requires key authentication and multi factor authentication.
Support
Submit all Mailer To Go support and runtime issues via one of the Heroku Support channels. Any non-support related issues or product feedback is welcome at support@mailertogo.com.