![](/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.