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 Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)