简体   繁体   中英

Sendgrid returns SMTP-AUTH requested but missing user name

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 => "do-not-reply@example.com"

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

 user_name: Rails.application.secrets.email_provider

with:

 user_name: Rails.application.secrets.email_provider_username

and the problem was solved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM