Liz*_*Liz 8 ruby-on-rails sendgrid
I'm trying to get a Rails 5.2 mailer working, but am coming across a Net::SMTPAuthenticationError - 535 Authentication failed: account disabled error on both localhost and my Heroku production environment.
The mailer looks like this:
class AdminNotificationsMailer < ApplicationMailer
default from: "liz@linchpinindustries.com"
def new_rfp(rfp)
@rfp = rfp
mail(
:to => "liz@linchpinindustries.com",
:subject => 'New RFP Alert!'
)
end
def new_contact_us(contact)
@contact = contact
mail(
to: "liz@linchpinindustries.com",
subject: 'New Contact Us Submission on LPI'
)
end
end
Run Code Online (Sandbox Code Playgroud)
With the trigger in my rfp#create action (for the first mailer, the new_rfp one):
def create
@rfp = Rfp.new(rfp_params)
respond_to do |format|
if @rfp.save!
AdminNotificationsMailer.new_rfp(@rfp).deliver
format.html { redirect_to root_path, notice: "Thanks for your request! We'll get back to you ASAP. Stay tuned!" }
format.json { render :show, status: :created, location: @rfp }
else
format.html { render :new }
format.json { render json: @rfp.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
I have provisioned Sendgrid and double checked my username and password with puts (it is correct on localhost and production).
I have the following in my environment.rb:
ActionMailer::Base.smtp_settings = {
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"],
:domain => 'linchpinindustries.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
我被正式难住了。谁能看出为什么会发生此错误?
您设置中的所有内容看起来都是正确的,所以这不仅仅是简单的
Net::SMTPAuthenticationError - 535 Authentication failed: account disabled
Run Code Online (Sandbox Code Playgroud)
无论出于何种原因,您的帐户都是如此disabled。与 Sendgrid 检查您的帐户是否已启动并正常运行。
我收到了类似的错误消息,问题是我在 sendgrid 上打开了 2FA 身份验证,但没有意识到在执行此操作时必须更新应用程序中的配置。
现在,您必须提供自定义用户名和密码,username = "apikey"而密码是您的 api 密钥
ActionMailer::Base.smtp_settings = {
domain: 'YOUR_DOMAIN.COM',
address: "smtp.sendgrid.net",
port: 587,
authentication: :plain,
user_name: 'apikey',
password: ENV['SENDGRID_API_KEY']
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3521 次 |
| 最近记录: |