Send Email

Rails makes it easy to send email. The ActionMailer gem is part of any
Rails installation.

Implementation of email closely follows the model-view-controller
architecture. To implement email, you’ll need:

    model
    view
    mailer

The “mailer” is similar to a controller, combining data attributes from
a model with a view file. Any methods we add to the mailer class can be
called from a controller, triggering delivery of an email message.

The model can be any we’ve already created. In this case, we’ll use the
Contact model, since it gives us access to the visitor’s name, email
address, and message.

We’ll create a mail-specific view file in the app/views/user_mailer/
folder. Our folder for mail-specific views will go in the app/views/
directory as a sibling of the app/views/layouts folder.

The Rails directory structure already gives us a folder app/mailers/ for
the mailer class and, not surprisingly, it is a sibling of the
app/controllers/ folder.

We don’t have to create the necessary folders and files manually, as the
rails generate command runs a utility to create what we need.