代码之家  ›  专栏  ›  技术社区  ›  Robert

执行操作邮件程序时,不会读取sendgrid用户名和密码环境变量

  •  1
  • Robert  · 技术社区  · 7 年前

    预期:

    telnet smtp.sendgrid.net 587 EHLO AUTH LOGIN Enter username in Base64 Enter password in Base64

    235 Authentication successful

    实际值:

    通过本地主机

    配置/环境/开发。rb型

    config.action_mailer.raise_delivery_errors = true
    

    配置/环境。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。环境

    export SENDGRID_USERNAME='apikey'
    export SENDGRID_PASSWORD='the api key that was provided during the smtp setup'
    

    现在我知道了

    source ./sendgrid.env
    

    我检查了环境,它显示了用户名/密码。

    rails c
    NotificationMailer.notification_email(@admin_email, @item).deliver
    

    我看到邮件被记录下来了,但我

    Net::SMTPFatalError: 550 Unauthenticated senders not allowed

    如果我对env变量进行硬编码,则验证确实有效。所以我不明白为什么ENV变量没有进入这个过程。

    请告知

    1 回复  |  直到 7 年前
        1
  •  0
  •   Robert    7 年前

    我使用dontenv rails gem解决了这个问题: https://github.com/bkeepers/dotenv