Net::SMTPAuthenticationError at /contacts 535-5.7.8 Username and Password not accepted Sinatra Ruby

174 Views Asked by At

When I send a simple form with Sinatra's help, it shows this error:

Net::SMTPAuthenticationError at /contacts 535-5.7.8 Username and Password not accepted Ruby Sinatra

What versions of the programs:

  • OS: Windows 7/64
  • Ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580) [x64-mingw32]

Gems included by the bundle:

  • backports (3.15.0)
  • bundler (2.0.2)
  • mail (2.7.1)
  • mini_mime (1.0.2)
  • multi_json (1.14.1)
  • pony (1.13.1)
  • rack (1.5.2)
  • rack-protection (1.5.1)
  • rack-test (1.1.0)
  • sinatra (1.4.4)
  • sinatra-contrib (1.4.7)
  • tilt (1.4.1)

And here is my code in sinatra's app.rb:

# app.rb
require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require "pony"

get '/' do
    erb "Hello! <a href=\"https://github.com/bootstrap-ruby/sinatra-bootstrap\">Original</a> pattern has been modified for <a href=\"http://rubyschool.us/\">Ruby School</a>"           
end

get "/contacts" do
    erb :contacts
end

post "/contacts" do
    login   = params[:login]
    message = params[:message]

Pony.mail({
  :to => '***1***@gmail.com',    # real mail 1
  :from => '***2***@gmail.com',  # real mail 2
  :via => :smtp,
  :subject => "New message from user: #{login}",
  :body => "#{message}",

  :via_options => {
    :address              => 'smtp.gmail.com',
    :port                 => '587',
    :enable_starttls_auto => true,
    :user_name            => '***2***@gmail.com', # real mail 2
    :password             => '**********',
    :authentication       => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain               => "gmail.com" # the HELO domain provided by the client to the server
    # :openssl_verify_mode => 'none' 
  }
})
  erb :contacts
end

And here is my code in sinatra's contacts.erb:

<body>
<h2> Feedback </h2>

<form action="/contacts" method="POST">
<div class="form-group">
  <label>Your name:</label>
  <input name="username" type="text" class="form-control" placeholder="Your name">
  <label for="comment">Text of the appeal:</label>
  <textarea name="message" class="form-control" rows="5" placeholder="Text of the appeal"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send:</button>
</form>

Backtrace:

 C:/Ruby26-x64/lib/ruby/2.6.0/net/smtp.rb in check_auth_response

            raise SMTPAuthenticationError, res.message

C:/Ruby26-x64/lib/ruby/2.6.0/net/smtp.rb in auth_plain

          check_auth_response res
0

There are 0 best solutions below