Tutorial

Send Email with Ruby on Rails via SMTP

Action Mailer, configured once in an initializer, sent from anywhere in your app.

By the Sendcorex team·Updated Sep 21, 2026·7 min read

Configure Action Mailer

In config/environments/production.rb (or an initializer):

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: 'smtp.sendcorex.com',
  port: 587,
  user_name: ENV['SENDCOREX_API_KEY'],
  password: ENV['SENDCOREX_API_KEY'],
  authentication: 'plain',
  enable_starttls_auto: true,
}
config.action_mailer.default_url_options = { host: 'yourdomain.com' }

Generate and send a mailer

rails generate mailer Welcome
class WelcomeMailer < ApplicationMailer
  default from: 'Your App <hello@yourdomain.com>'

  def welcome_email(user)
    @user = user
    mail(to: @user.email, subject: 'Welcome!')
  end
end

# from anywhere in your app
WelcomeMailer.welcome_email(user).deliver_later

Use deliver_later with a queue adapter (Sidekiq, Solid Queue) instead of deliver_now so a slow SMTP connection never blocks a web request.

Common errors

SymptomFix
Net::SMTPAuthenticationErrorConfirm the env var is loaded and used for both user_name and password.
Mail never leaves the queueCheck your queue adapter (e.g. Sidekiq) is actually running in that environment.

Send your first email in minutes

Create a free account, verify your domain and paste in the code above.

No credit card required