Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

ruby on rails - Running into SMTP error when trying to send email in RoR app

I've been desperately trying to send an email using the Action Mailer class in RoR, and even though the terminal shows that a message is being sent, it keeps returning with this error:

 et::SMTPAuthenticationError: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbtOS

from /Users/abhasarya/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:968:in `check_auth_response'
from /Users/abhasarya/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:739:in `auth_plain'
from /Users/abhasarya/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:731:in `authenticate'...

Here's what my mailer class looks like within app/mailers/my_mailer.rb:

class MyMailer < ActionMailer::Base
  default from: "[email protected]"

  def welcome_email(user) 
    @user = user

        mail(to: user.email,
             from: '[email protected]',
             subject: 'Welcome!')
  end
end

And here's what my config/application.rb file looks like:

config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {

        address:              'smtp.gmail.com',
        port:                 587,
        #domain:               'gmail.com',
        user_name:            '[email protected]',
        password:             'my_password',
        authentication:       'plain',
        enable_starttls_auto: true  

        }

        config.action_mailer.default_url_options = {
            :host => "localhost",
            :port => 3000
        }

in my config/environments/development.rb file I also have these two lines:

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true

My problem is that whenever I start the rails console (working in development, have no idea how to run in production), assign a user's email to the user variable then enter the command: MyMailer.welcome_email(user).deliver

the terminal says:

Rendered my_mailer/welcome_email.html.erb (11.7ms)
  Rendered my_mailer/welcome_email.text.erb (0.5ms)

Sent mail to [email protected] (923.1ms)
Date: Fri, 08 Aug 2014 13:54:38 -0400
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Welcome!
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_53e50eded7355_2b0b8082dbf85068f";
 charset=UTF-8
Content-Transfer-Encoding: 7bit

but then renders the error. My views are simple enough that I didn't think I needed to include them here. I've desperately tried everything, including unlocking google captcha but still nothing works. I'd appreciate any help, all I want is for an email to get sent to the proper inbox. I'd love you forever if you can solve this issue!!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The reason that you are seeing this error is that Google has blocked your IP. You will need to enable authorization for this IP.

Go to http://www.google.com/accounts/DisplayUnlockCaptcha and click continue.

Then again try to send email from the application, it should work. You will need to send email from your app within 10 min of visiting the above link. By visiting above link, Google will grant access to register new apps for 10 min.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...