Sendgrid返回请求的SMTP-AUTH,但缺少用户名

问题描述:

我是Ruby on Rails的新手,我按照Daniel Kehoe的“学习ruby-on-rails”一书。我已经在Ubuntu环境中正确设置了我的sengrid登录信息。 echo $ SENDGRID_USERNAME正确返回我的用户名。Sendgrid返回请求的SMTP-AUTH,但缺少用户名

但是,当我提交联系表单时,仍然出现“SMTP-AUTH请求但缺少用户名”错误。我试图硬编码的登录细节,我仍然得到相同的错误。我的配置设置我smtp.sendgrid.net在端口587上,我允许发送邮件发送。

请问我没做对。 非常感谢。

我user_mailer.rb是如下所示:

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 

而contacts_controller.rb如下所示:

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 

问题从出现省略config/enviroments/development.rb文件 我换成

user_name: Rails.application.secrets.email_provider 

有:

user_name: Rails.application.secrets.email_provider_username 

,问题就解决了