我是ruby on rails的新手,我阅读了Daniel Kehoe的Learn-ruby-on-rails这本书。我已经在Ubuntu环境中正确设置了我的sengrid登录详细信息。echo $ SENDGRID_USERNAME正确地返回了我的用户名。
但是,当我提交联系人表单时,仍然收到"SMTP-AUTH requested user name“错误。我已经尝试对登录详细信息进行硬编码,但仍然收到相同的错误。我的配置设置在端口587上使用smtp.sendgrid.net,并且我允许在开发中发送邮件。
请问我做错了什么。非常感谢。
我的user_mailer.rb如下所示:
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
结束
而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
结束
发布于 2016-04-25 23:39:54
这个问题是由我替换的config/enviroments/development.rb文件中的遗漏引起的
user_name: Rails.application.secrets.email_provider
通过以下方式:
user_name: Rails.application.secrets.email_provider_username
问题就解决了
https://stackoverflow.com/questions/36769142
复制相似问题