LettermintLettermint
  • Knowledge base
  • Community
  • Changelog
  • Support
  • Documentation
  • Sending API
  • Team API
Getting started
Guides
    Node.jsPHPPythonGoLaravelMagento 2NuxtJava
    SMTP
      IntroductionPHPMailerNodemailerPython (smtplib)Ruby (Mail)Golang
Platform
Resources
SMTP

Ruby (Mail)

This guide covers SMTP integration. For full configuration options and available headers, see the SMTP Introduction.

Installation

TerminalCode
gem install mail

Or add to your Gemfile:

Code
gem 'mail'

Basic Configuration

Use environment variables for credentials:

Code
SMTP_HOST = 'smtp.lettermint.co' SMTP_USERNAME = 'lettermint' API_TOKEN = ENV['LETTERMINT_PROJECT_TOKEN']

Advanced Features

Multiple Recipients

Code
mail = Mail.new do from 'sender@yourdomain.com' to ['user1@example.com', 'user2@example.com'] cc 'manager@yourdomain.com' bcc 'archive@yourdomain.com' subject 'Newsletter' body '<h1>Monthly Update</h1>' end

Attachments

Code
mail = Mail.new do from 'sender@yourdomain.com' to 'recipient@example.com' subject 'Document Attached' body 'Please find the document attached.' add_file '/path/to/document.pdf' add_file filename: 'data.txt', content: 'Custom content' end

Custom Headers

Code
mail = Mail.new do from 'sender@yourdomain.com' to 'recipient@example.com' subject 'Custom Headers' body 'Email with custom headers.' header['X-Priority'] = '1' header['X-Custom-Header'] = 'Custom Value' end

Metadata for Tracking

Add metadata that will be included in webhook payloads:

Code
mail = Mail.new do from 'sender@yourdomain.com' to 'recipient@example.com' subject 'Order Confirmation' body 'Your order has been confirmed.' header['X-LM-Metadata-order_id'] = '12345' header['X-LM-Metadata-customer_id'] = 'cust_789' header['X-LM-Metadata-campaign'] = 'order_confirmation' end

Lettermint Headers

Add Lettermint-specific headers for tags and routing:

Code
mail = Mail.new do from 'sender@yourdomain.com' to 'recipient@example.com' subject 'Order Confirmation' body 'Your order has been confirmed.' # Tag for categorization header['X-LM-Tag'] = 'order-confirmation' # Metadata for tracking (included in webhooks) header['X-LM-Metadata-order_id'] = '12345' header['X-LM-Metadata-customer_id'] = 'cust_789' # Route selection header['X-Lettermint-Route'] = 'transactional' end

Metadata headers are extracted by Lettermint and included in webhook payloads, but not added to the actual email sent to recipients. See the SMTP Introduction for full details on available headers.

Rails Integration

In config/environments/production.rb:

Code
config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.lettermint.co', port: 587, user_name: 'lettermint', password: ENV['LETTERMINT_PROJECT_TOKEN'], authentication: 'plain', enable_starttls_auto: true }
Last modified on May 11, 2026
Python (smtplib)Golang
On this page
  • Installation
  • Basic Configuration
  • Advanced Features
    • Multiple Recipients
    • Attachments
    • Custom Headers
    • Metadata for Tracking
    • Lettermint Headers
  • Rails Integration
Ruby
Ruby
require 'mail' Mail.defaults do delivery_method :smtp, { address: 'smtp.lettermint.co', port: 587, user_name: 'lettermint', password: ENV['LETTERMINT_PROJECT_TOKEN'], authentication: 'plain', enable_starttls_auto: true } end mail = Mail.new do from 'sender@yourdomain.com' to 'recipient@example.com' subject 'Test Email' text_part do body 'Hello! This is a test email.' end html_part do content_type 'text/html; charset=UTF-8' body '<h1>Hello!</h1><p>This is a test email.</p>' end end mail.deliver!
Ruby
Ruby
Ruby
Ruby
Ruby
Ruby