3

I am trying to generate a basic email using ActionMailer. I know that things are setup semi-correctly, as I received an email from Gmail saying an unsecure app tried to login to my account. I have done as others said in this post. Those steps are:

1) Enabled less-secure apps setting in Gmail settings.
2) Changed domain: to "gmail.com" from "mydomainname.com"
3) Changed authentication from "plain" to :login
4) In Gmail settings, enabled POP and IMAP.

Here is my development configuration setting for mail:
...config/environments/development.rb

  config.action_mailer.raise_delivery_errors = true

  #change mail delivery to smtp for Gmail addresses.
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: "gmail.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: ENV["GMAIL_USERNAME"],
    password: ENV["GMAIL_PASSWORD"]
  }

I've even set the environment variables like a good boy. Error persists even if I hard code the values.

And the exception I get is:

Net::SMTPAuthenticationError  
534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtj
S. Harper
  • 167
  • 9

3 Answers3

2

Also, in development you can use local mail-catchers.

One of them is MailHog, it's similar to gmail.

Installation

brew update && brew install mailhog

development.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }

Run MailHog in terminal typing: MailHog and in a browser http://localhost:8025

7urkm3n
  • 6,054
  • 4
  • 29
  • 46
1

What fixed it is playing around with the settings until I finally got:

  config.action_mailer.raise_delivery_errors = true

  #change mail delivery to smtp for Gmail addresses.
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: "mydomainname.com",
    authentication: "login",
    enable_starttls_auto: true,
    user_name: ENV["GMAIL_USERNAME"],
    password: ENV["GMAIL_PASSWORD"]
  }

But the real kicker was to make sure and restart the server with each change to the ...config/environments/development.rb file above.

Edit: Well, now I feel like i'm going crazy, because the above settings did not work when I tried to run it again...

S. Harper
  • 167
  • 9
1

Not really a solution to Gmail's configuration problem, but another option. I had the same problem and solved it. And the problem eventually appeared again. I'm not sure if I changed something or if it´s just Gmail who doesn't like less secure applications and blocks emails even if you configure everything correctly.

I read other people solved the problem (https://stackoverflow.com/a/48300220/3372172) using two steps authentication, but never tried it.

I finally changed to another ESP (as even Rails seems to recommend in their guides): http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration-for-gmail

Note: As of July 15, 2014, Google increased its security measures and now blocks attempts from apps it deems less secure. You can change your gmail settings here to allow the attempts. If your Gmail account has 2-factor authentication enabled, then you will need to set an app password and use that instead of your regular password. Alternatively, you can use another ESP to send email by replacing 'smtp.gmail.com' above with the address of your provider.

I am using Sengrid because their free plan (100 daily emails) is enough for me right now and I get many interesting analytics. But if you need more volume, I don't think they are cheap.

Pablo
  • 3,004
  • 1
  • 12
  • 19
  • I'm glad i'm not the only one it came back for. Finally got it to go away a second time, but have no idea what I did. I'll try the two-step auth next if it comes back. Thanks for including the official documentation in the answer. – S. Harper Feb 15 '18 at 02:01
  • AmazonSES is really cheap, 60K emails for free if to deploy in EC2. Most email SAAServices uses AmazonSES also. – 7urkm3n Feb 15 '18 at 04:27