Read more

ActionMailer: How to send a test mail directly from the console

Daniel Straßner
April 24, 2018Software engineer at makandra GmbH

If your rails application is unable to send mails, it might be useful to debug your settings using the rails console. Here is a snippet that shows the current settings and lets you send a test mail directly from the console:

mailer = ActionMailer::Base.new

# check settings:
mailer.delivery_method # -> :smtp
mailer.smtp_settings # -> { address: "localhost", port: 25, domain: "localhost.localdomain", user_name: nil, password: nil, authentication: nil, enable_starttls_auto: true }

# send mail:
mailer.mail(from: 'sender@example.com', to: 'recipient@example.com', subject: 'test', body: "Hello, you've got mail!").deliver
Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

You could use this to test the spam score of your emails, e.g. by using an existing mailer:

ActionMailer::Base.default_url_options[:protocol] = 'https'
ActionMailer::Base.default_url_options[:host] = '<your production domain>'

user = User.first
user.email = '<your mail address of mail-tester.com>' # do not save!

UserMailer.welcome(user).deliver_now

Posted by Daniel Straßner to makandra dev (2018-04-24 09:25)