guides
Ruby Send Email SMTP Guide (Net::SMTP + Production Checklist)
Send email with Ruby SMTP using Net::SMTP, authenticated transport, and test-ready patterns for transactional and QA-critical workflows.
If you searched for ruby send email smtp, the production-safe path is:
- use
Net::SMTPwith explicit auth/TLS settings - externalize SMTP config per environment
- assert real inbox outcomes in tests
- run deliverability diagnostics before release

Quick setup with Net::SMTP
require 'net/smtp'
message = <<~MESSAGE
From: no-reply@example.com
To: user@example.com
Subject: Welcome
Your account is ready.
MESSAGE
Net::SMTP.start(
'smtp.example.com',
587,
'example.com',
'smtp-user',
'smtp-password',
:plain
) do |smtp|
smtp.send_message(message, 'no-reply@example.com', 'user@example.com')
end
SMTP settings Ruby teams should lock down
Define and validate:
- SMTP host and port
- authentication mode (
:plain,:login, or provider-required mode) - TLS/STARTTLS transport expectations
- sender-domain alignment for SPF, DKIM, and DMARC
- timeout and retry behavior for transient failures
Related references:
Environment-driven Ruby SMTP configuration
require 'net/smtp'
host = ENV.fetch('SMTP_HOST')
port = Integer(ENV.fetch('SMTP_PORT'))
user = ENV.fetch('SMTP_USERNAME')
pass = ENV.fetch('SMTP_PASSWORD')
from = ENV.fetch('SMTP_FROM_ADDRESS')
to = 'recipient@example.com'
message = <<~MESSAGE
From: #{from}
To: #{to}
Subject: SMTP test
This is a production-style SMTP send test.
MESSAGE
Net::SMTP.start(host, port, 'example.com', user, pass, :plain) do |smtp|
smtp.send_message(message, from, to)
end
This keeps secrets out of code and makes staging/production parity easier.
Common Ruby SMTP failures and fixes
Authentication errors
Likely causes:
- invalid credentials
- wrong auth mode
- sender-domain policy mismatch
Fixes:
- verify credential source and rotation timing
- confirm auth mechanism expected by provider
- validate sender-domain authentication posture
TLS/connection failures
Likely causes:
- wrong port/transport expectations
- blocked outbound network egress
- certificate or trust-chain mismatch
Fixes:
- confirm port and TLS requirements
- verify firewall/egress policy
- align transport mode with provider docs
SMTP accepted but message not visible in inbox
Transport success is not the same as inbox placement.
Add diagnostics:
Test Ruby SMTP workflows before release
Run deterministic inbox tests for:
- account verification flows
- password reset flows
- billing and receipt messages
- alert and support notifications
Recommended workflow pages:
Ruby SMTP production checklist
- Use env-driven SMTP host/port/auth configuration.
- Validate sender-domain SPF/DKIM/DMARC alignment.
- Add inbox-based assertions for release-critical paths.
- Add retry and timeout controls for transient failures.
- Re-test after DNS, template, or provider changes.
FAQ
Can Ruby send SMTP email without external gems?
Yes. Net::SMTP is part of Ruby's standard library and is enough for many transactional workflows.
Which Ruby SMTP auth mode should I use?
Use the mode your provider requires. :plain and :login are common, but you should verify this in provider docs.
How do I validate Ruby SMTP reliably in CI?
Use isolated inboxes and deterministic receive assertions, not just successful SMTP transport calls.