预期:
telnet smtp.sendgrid.net 587
EHLO
AUTH LOGIN
Enter username in Base64
Enter password in Base64
235 Authentication successful
实际值:
通过localhost
配置/环境/ 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变量没有进入这个过程。
请告知