Mail

Witam,
Mam problem z mail_form’em. Otóż:

    Net::SMTPAuthenticationError
      in ContactsController#create
  530-5.5.1 Authentication Required. Learn more at

Próbowałem zastosować teoretyczne rozwiązania podane w internetach, ale żadne nie zadziałało. Włączyłem w swoim profilu gmaila obsługe inny appek i pozwolenie na inne połączenia.

development.rb

config.assets.raise_runtime_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp



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

application.yml

GMAIL_DOMAIN: tu jest emial
GMAIL_USERNAME: login gmail
GMAIL_PASSWORD: haslo

cantacts_controller.rb

class ContactsController < ApplicationController
  def new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    if @contact.deliver
      flash.now[:error] = nil
    else
      flash.now[:error] = 'Connot send message.'
      render :new
    end
  end


def contact
    params.require(:contact).permit(:nazwa, :email, :message, :nickname)
  end

end

contact.rb

class Contact < MailForm::Base
  attribute :nazwa, :validate => true
  attribute :email, :validate => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
  attribute :message, :validate => true
  attribute :nickname, :captcha => true

def headers
        {

          :subject => "Contact Form",
           :to => "maricha177@gmail.com",
           :from => %("#{nazwa}" <#{email}>)
        }
      end
end

Logi

Started GET "/contacts/new" for 127.0.0.1 at 2015-12-16 18:43:56 +0100
Processing by ContactsController#new as HTML
  Rendered contacts/new.html.erb within layouts/application (2.0ms)
Completed 200 OK in 62ms (Views: 62.0ms | ActiveRecord: 0.0ms)


Started POST "/contacts" for 127.0.0.1 at 2015-12-16 18:44:00 +0100
Processing by ContactsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"kJIDp2vJ2GTQZjlZWb76XQMVvSfSbelwHW2oHtSQbHs=", "contact"=>{"nazwa"=>"Romek", "email"=>"dfgdfg@fsgdfh.pl", "message"=>"fghfhfhfgh", "nickname"=>""}, "commit"=>"Wyśli wiadomość"}
  Rendered D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/mail_form-1.5.1/lib/mail_form/views/mail_form/contact.erb (1.0ms)

MailForm::Notifier#contact: processed outbound mail in 24.0ms

Sent mail to maricha177@gmail.com (632.0ms)
Date: Wed, 16 Dec 2015 18:44:00 +0100
From: Romek <dfgdfg@fsgdfh.pl>
To: maricha177@gmail.com
Message-ID: <5671a2e0db817_10103b2f60897586@Marcin-Komputer.mail>
Subject: Contact Form
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<h4 style="text-decoration:underline">Contact Form</h4>


  <p><b>Nazwa:</b>
  Romek</p>

  <p><b>Email:</b>
  dfgdfg@fsgdfh.pl</p>

  <p><b>Message:</b>
  fghfhfhfgh</p>


Completed 500 Internal Server Error in 660ms

Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at
):
  app/controllers/contacts_controller.rb:9:in `create'


  Rendered D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.0ms)
  Rendered D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.0ms)
  Rendered D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)
  Rendered D:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (32.0ms)

Z góry dziękuje za pomoc. :smile:

Hmmm, według http://guides.rubyonrails.org/action_mailer_basics.html 6.2 w :domain powinieneś mieć domenę a nie email, spróbuj też, jeśli już tak nie masz podać zamiast loginu - całego maila pod :user_name. To jedyne różnice w stosunku do mojej gmailowej konfiguracji.

1 Like

Zmieniłem, ale bląd ten sam.

Przeładowałeś serwer?

To znaczy? xD

No czy ubiłeś proces i wystartowałeś ponownie? Te konfiguracje są ładowane tylko w chwili kiedy odpalany jest serwer (rails s)

Tak, tak.

Nic to nie dało

Spróbuj może http://stackoverflow.com/questions/27437469/530-5-5-1-authentication-required-learn-more-at

Nadal to samo… Damn.

Nie jestem pewien czy to jest związane, ale gmail wymaga żeby we :from był adres konta na jakie się logujesz. Wydaje mi się, że wtedy wypluwało odpowiedni error, ale głowy nie dam.

W jaki sposób to, co masz w application.yml jest ładowane do ENV? Upewnij się, że w ENV faktycznie są prawidłowe dane.

1 Like

Zainstalowałem gem Figaro. Według dokumentacji niby to ma tak wyglądać.

Rozwiązałem problem… brakowało jednego pliku konfiguracji env figaro… eh…
Dzięki za wszelkie odpowiedzi :smile:

sprobuj ustawic na skrzynce pocztowej gmail ,ktora chcesz wysylac maile, aby pozwalala na dostep “mniej bezpiecznym aplikacjom”

moim zdaniem tutaj masz ten problem.

1 Like