I am new to ruby on rails and I follow the book Learn-ruby-on-rails by Daniel Kehoe. I have set up my sengrid login details correctly on the Ubuntu enviroment. echo $ SENDGRID_USERNAME returns my username correctly.
However, I still get "SMTP-AUTH requested but missing user name" error when I submit the contact form. I have tried to hardcode the login details and I still get the same errors. my configuration settings i smtp.sendgrid.net on port 587 and I allow send mails in development.
Please what am I not doing right. Thanks a lot.
My user_mailer.rb is as shown:
class UserMailer < ActionMailer::Base
#default :from => "[email protected]"
def contact_email(contact)
@contact = contact
mail( to: => Rails.application.secrets.owner_email, from: => @contact.email, subject: => "Website Visit")
end
end
while the contacts_controller.rb is shown below:
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(secure_params)
if @contact.valid?
UserMailer.contact_email(@contact).deliver_now
#TODO send message
flash[:notice] = "Message sent from #{@contact.name}."
redirect_to root_path
else
render :new
end
end
private
def secure_params
params.require(:contact).permit(:name, :email, :content)
end
end
The problem arose from an omission in the config/enviroments/development.rb file I replaced
with:
and the problem was solved