← Blog

How to Send Email in Ruby, Python, Node.js & Go With Mailer To Go

Guide SMTP, API, Ruby, Python, Node.js, Go July 9, 2026 by Mailer To Go Team
How to send transactional email through Mailer To Go over SMTP, with working code samples in Ruby, Python, Node.js, and Go — plus production tips and a preview of the REST API in development.

The way to send transactional email through Mailer To Go today is SMTP: point your framework’s built-in mailer at our submission endpoint and you’re sending in minutes, from any language. This guide has working examples in Ruby, Python, Node.js, and Go. (A JSON REST API is in development — see the note at the end.)

Everything here is the data plane — actually sending mail. The control plane (delivery/bounce events, inbound receiving, and provisioning) is a separate surface with its own guide coming later.

Get your credentials

From your dashboard, grab your SMTP username and password, and set them as environment variables. On Heroku and Build.io these are set as config vars automatically when you provision the add-on.

export MAILERTOGO_SMTP_HOST=smtp.mailertogo.com   # the exact host is shown in your dashboard
export MAILERTOGO_SMTP_USER=...                    # from dashboard
export MAILERTOGO_SMTP_PASSWORD=...                # from dashboard

Send from an address on a domain you’ve verified (see domain setup and authentication); Mailer To Go rejects unverified From: domains.

Send over SMTP

SMTP host from your dashboard, port 587 (STARTTLS) or 465 (SSL). Because it’s standard SMTP, your language’s built-in mailer already speaks it.

Ruby (the mail gem):

require "mail"

Mail.defaults do
  delivery_method :smtp,
    address:              ENV["MAILERTOGO_SMTP_HOST"], port: 587,
    user_name:            ENV["MAILERTOGO_SMTP_USER"],
    password:             ENV["MAILERTOGO_SMTP_PASSWORD"],
    authentication:       :plain, enable_starttls_auto: true
end

Mail.deliver do
  from    "Acme <hello@yourdomain.com>"
  to      "user@example.com"
  subject "Hello from Ruby"
  body    "Your email body here."
end

Python (standard library smtplib):

import os, smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg["From"] = "Acme <hello@yourdomain.com>"
msg["To"] = "user@example.com"
msg["Subject"] = "Hello from Python"
msg.set_content("Your email body here.")

with smtplib.SMTP(os.environ["MAILERTOGO_SMTP_HOST"], 587) as s:
    s.starttls()
    s.login(os.environ["MAILERTOGO_SMTP_USER"], os.environ["MAILERTOGO_SMTP_PASSWORD"])
    s.send_message(msg)

Node.js (Nodemailer):

const nodemailer = require("nodemailer");

const transport = nodemailer.createTransport({
  host: process.env.MAILERTOGO_SMTP_HOST,
  port: 587,
  auth: { user: process.env.MAILERTOGO_SMTP_USER, pass: process.env.MAILERTOGO_SMTP_PASSWORD },
});

await transport.sendMail({
  from: "Acme <hello@yourdomain.com>",
  to: "user@example.com",
  subject: "Hello from Node",
  text: "Your email body here.",
});

Go (standard library net/smtp):

package main

import (
	"net/smtp"
	"os"
)

func main() {
	host := os.Getenv("MAILERTOGO_SMTP_HOST")
	auth := smtp.PlainAuth("", os.Getenv("MAILERTOGO_SMTP_USER"), os.Getenv("MAILERTOGO_SMTP_PASSWORD"), host)
	msg := []byte("To: user@example.com\r\n" +
		"From: Acme <hello@yourdomain.com>\r\n" +
		"Subject: Hello from Go\r\n\r\n" +
		"Your email body here.\r\n")
	if err := smtp.SendMail(host+":587", auth, "hello@yourdomain.com", []string{"user@example.com"}, msg); err != nil {
		panic(err)
	}
}

Sending HTML instead of plain text? Set the HTML part of the message (html_part in the Ruby mail gem, add_alternative(..., subtype="html") in Python, the html field in Nodemailer, or a Content-Type: text/html header in Go) — everything else stays the same.

Production tips

A REST API is in development

For teams that would rather make an HTTP call than hold an SMTP connection, a JSON send API is on the way. The planned shape:

POST https://api.mailertogo.com/api/v1/emails
Authorization: Bearer <your API key>
Content-Type: application/json

{
  "from": "hello@yourdomain.com",
  "to": "user@example.com",          // or an array, up to 50 recipients
  "subject": "Hello",
  "html": "...", "text": "...",       // provide either or both
  "reply_to": "support@yourdomain.com",
  "tags": [ { "name": "campaign", "value": "welcome" } ]
}

It will return the queued message’s id. This endpoint isn’t live yet — send over SMTP today, and we’ll update this post when the REST API ships. (The broader control-plane API — events, inbound receiving, provisioning — is tracked separately.)


Deploying on a specific platform? See Send transactional email from Heroku. Migrating from another provider? See the guides for SendGrid, Mailgun, and Amazon SES.