【发布时间】:2018-06-16 18:28:21
【问题描述】:
预期:
telnet smtp.sendgrid.net 587
EHLO
AUTH LOGIN
Enter username in Base64
Enter password in Base64
235 Authentication successful
实际:
通过本地主机
config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config/environment.rb
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
port: 587,
domain: 'example.com',
user_name: ENV["SENDGRID_USERNAME"],
password: ENV["SENDGRID_PASSWORD"],
authentication: 'plain',
enable_starttls_auto: true
}
控制器
NotificationMailer.notification_email(@admin_email, @item).deliver
sendgrid.env
export SENDGRID_USERNAME='apikey'
export SENDGRID_PASSWORD='the api key that was provided during the smtp setup'
现在可以了
source ./sendgrid.env
我检查了 ENV,它显示了用户名/密码。
rails c
NotificationMailer.notification_email(@admin_email, @item).deliver
我看到电子邮件被记录了,但我收到了
Net::SMTPFatalError: 550 Unauthenticated senders not allowed
如果我对 env 变量进行硬编码,则身份验证确实有效。所以我不明白为什么 ENV 变量没有进入这个过程。
请指教
【问题讨论】:
标签: ruby-on-rails smtp environment-variables sendgrid