ActionMailer

Test out your mails locally

See a list of all your ActiveMailer templates and test them locally

http://localhost:3000/rails/mailers

ActionMailer works just like ActionController

Method names correspond to view names.

Urls are special cases in Mailer views

From the docs

Unlike controllers, the mailer instance doesn’t have any context about the incoming request so you’ll need to provide the :host parameter yourself.

As the :host usually is consistent across the application you can configure it globally in config/application.rb:

config.action_mailer.default_url_options = { host: 'example.com' }

Because of this behavior you cannot use any of the *path helpers inside of an email. Instead you will need to use the associated *url helper. For example instead of using

<%= link_to 'welcome', welcome_path %>

You will need to use

<%= link_to 'welcome', welcome_url %>

Mostly Katie explaining things to herself.

© 2022