![](/img/trans.png)
[英]Rails 6 ArgumentError (SMTP-AUTH requested but missing user name)
[英]Sendgrid returns SMTP-AUTH requested but missing user name
我是铁路上的红宝石新手,并且我遵循Daniel Kehoe撰写的《沿路学习红宝石》一书。 我已经在Ubuntu环境中正确设置了我的Sengrid登录详细信息。 echo $ SENDGRID_USERNAME正确返回我的用户名。
但是,当我提交联系表时,仍然出现“请求SMTP-AUTH但缺少用户名”的错误。 我尝试对登录详细信息进行硬编码,但仍然出现相同的错误。 我的配置设置是在端口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
结束
问题是由我替换的config / enviroments / development.rb文件中的遗漏引起的
user_name: Rails.application.secrets.email_provider
与:
user_name: Rails.application.secrets.email_provider_username
问题解决了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.