Search⌘ K
AI Features

Send an Order Confirmation Email

Explore how to build and integrate an order confirmation email using a Rails mailer. Learn to generate the mailer, define the send_confirmation method, create HTML and text views, add testing, and connect the mailer to the order creation process to notify users effectively.

We will create a mailer model to send a confirmation email to the user who places an order. This model will allow us to send data through email protocols. If you want to skip this lesson and jump into the next chapter, go ahead. This section is more of a warm-up.

Generate mailer

We must first create the order_mailer with an email named send_confirmation by using the command in the terminal below:

$ rails generate mailer order_mailer send_confirmation
Terminal 1
Terminal
Loading...

The output will look something like this:

Running via Spring preloader in process 29
      create  app/mailers/order_mailer.rb
      invoke  erb
      create   
...