Action Mailer Configurations

| Comments

This week, I started working on a presentation with two other girls, Laura Brown and Ana Becker to present at the NYC on Rails meetup this coming Thursday (March 28). Our app revolves around using ActionMailer. And this was the first time I’ve tried to use the gem.

The documentation for it is really good, and the implementation doesn’t require too many steps. RailsGuides has a great step by step breakdown of the entire process, inluding the steps for generating a Mailer.

All of that was easy. I only wanted to render a default template in my view, and am staying away from user authentication.

My problem fell in the configurations. I had no idea that I had to setup SMTP configurations to send my email. And then once I figured that out, where do I enter my specific configurations.

Step 1:
At first we weren’t getting any errors. It seemed as if our app was sending emails…but no one was getting any of them. The first thing we had to do was edit config/evironments/development.rb. That file contains the line:

  config.action_mailer.raise_delivery_errors = false

which needs to be changed to read:

  config.action_mailer.raise_delivery_errors = true

And then we started to get errors we could work from.

Step 2:
Because we’re using a Gmail account for our gem, we had to configure ActionMailer specifically for that account. The first step to that was to include the following two lines:

config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp

These lines delcares that SMTP will deliver our emails. SMTP stands for Simple Mail Transfer Protocol. This protocol also has a layer of authentication built into it’s functionality

Step 3:
The next step is to declare your specific SMTP configurations.

 config.action_mailer.smtp_settings = {
  :address => 'smtp.gmail.com',
  :port => 587,
  :domain => 'localhost:3000',
  :authentication => :plain,
  :user_name => '<email_address>',
  :password => '<email_password>',
  :authentication => 'plain',
  :enable_starttls_auto => true
}

These configurations state that we’re using Gmail, we’re running our app on localhost:3000, and also includes the email address and password for that account that are associated with the app. The last two lines of the settings handle the authentication of the email account.

And that’s it!

Comments