1

I have a rails project which sends an email using an ActionMailer. This seems to work fine with 'rails server' on localhost:3000 but when I use pow, I get authentication error messages from the smtp server. I'm guessing this has something to do with environment variables. Here is the config code

 config.action_mailer.smtp_settings = {
 address: "smtp.gmail.com",
 port: 587,
 domain: "railscasts.com",
 authentication: "plain",
 enable_starttls_auto: true,
 user_name: ENV["GMAIL_USERNAME"],
 password: ENV["GMAIL_PASSWORD"]
}

I'm on Mountain Lion.

Thanks

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Tushar S
  • 352
  • 1
  • 6
  • 15

3 Answers3

2

I have a different suggestion:

In dev, just use letter_opener. It's more useful in that context than actually sending emails, anyway.

In production, use SendGrid and not GMail. SendGrid is awesome and really easy to set up.

Jason Swett
  • 43,526
  • 67
  • 220
  • 351
  • Letter opener looks cool. However, SendGrid is too heavy for my needs. Mine is just a hobby project basically. – Tushar S Feb 15 '13 at 00:38
2

Pow loads environment variables from checking two files in the application root

  1. .powrc
  2. .powenv

I created the .powrc file using the touch command, then added my environment variables

export GMAIL_USERNAME=username
export GMAIL_PASSWORD="my password"

I then restarted the worker for the app this way:

touch tmp/restart.txt

E-mails now work!

Tushar S
  • 352
  • 1
  • 6
  • 15
  • For my and anyone elses reference (because it was not so simple to understand for me at the beginning): Use the variables in .powrc as Tushar described, but then in your environment file (e.g. development.rb) use `ENV["GMAIL_USERNAME"]` as your username (or whatever you call your variable). Same goes for your password. Probably I'm just lame and this is clear to everyone, but it may be useful for beginners :) – kellins Sep 19 '14 at 06:35
1

As blamattina has suggested, it may have something to do with your domain in your configuration file! According to the example given by Ruby on Rails Guides:

The correct, Gmail compatible configuration looks like this:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address              => "smtp.gmail.com",
:port                 => 587,
:domain               => 'baci.lindsaar.net',
:user_name            => '<username>',
:password             => '<password>',
:authentication       => 'plain',
:enable_starttls_auto => true  }

Your domain is set to railscasts.com. Unless that's your website, my guess is that this domain is not correct. In fact, it is apparently optional as well.

This StackOverflow details that a plugin was once necessary, but is no longer needed if you're using Rails 3.2 or higher. A comment below the top answer in the article details that the domain is optional.

Update: Based on the error you described, it looks like you're hitting an authentication error! This may be because of your login credentials not properly registering.

This user is asking in the context of using Heroku, but the error is the same. If your app works properly with the Rails server, but not on Pow, it's a server-side setup issue. The solution involves needing to properly set your ENV (environment) variables to work with your server.

Community
  • 1
  • 1
Jordan Thornquest
  • 1,056
  • 2
  • 12
  • 28
  • I tried getting rid of the domain and it still doesn't work. The specific error message is this Net::SMTPAuthenticationError in SubscribersController#send_email 530-5.5.1 Authentication Required. Learn more at – Tushar S Feb 08 '13 at 04:54
  • 1
    This may answer your problem! If it's an authentication error you're encountering, it may be because of your login credentials not properly registering: http://stackoverflow.com/questions/11302900/mailer-authentication-error-in-rails-3-2-with-gmail-or-sendgrid This user is asking in the context of using Heroku, but the error is the same. It may involve needing to properly set your `ENV` (environment) variables. First, try setting the Username and Password without the ENV prefixes. – Jordan Thornquest Feb 08 '13 at 17:27