【问题标题】:Redmine email configuration with environment variables使用环境变量进行 Redmine 电子邮件配置
【发布时间】:2013-02-09 07:43:10
【问题描述】:

我已经按照 redmine wiki 中的说明在 redmine 上配置了电子邮件,一切正常。以下是我的 config/configuration.yml 文件的内容:

production:
delivery_method: :smtp
 smtp_settings:
    address: "smtp.sendgrid.net"
    port: 587
    authentication: :plain
    domain: "heroku.com"
    user_name: my_email@gmail.com
    password: my_password 

但是我正在尝试使用环境变量代替 my_email@gmail.com 和 my_password,如下所示:

production:
  delivery_method: :smtp
  smtp_settings:
    address: "smtp.sendgrid.net"
    port: 587
    authentication: :plain
    domain: "heroku.com"
    user_name: <%= ENV['SENDGRID_USERNAME'] %>
    password: <%= ENV['SENDGRID_PASSWORD'] %>

当我尝试使用配置文件中的环境变量发送测试电子邮件时,redmine 给出此错误:

'发送邮件时出错(535 身份验证失败:用户名/密码错误)'。

所以我猜想 erb sn-p 没有被评估(我已经仔细检查了环境变量的值)。

我已经搜索了一个解决方案,但结果是空的,有没有人对我应该如何在 redmine 中配置电子邮件有任何建议,这样我就不会在配置文件中公开我的 sendgrid 凭据?

或者,如果有人可以告诉我直接使用凭据不存在安全风险,而无需环境变量,那也可以解决我的问题。

【问题讨论】:

    标签: ruby-on-rails email environment-variables redmine


    【解决方案1】:

    我在 2 周前回答了这个问题,然后立即被其他人删除。 所以我不确定是否有人会再次删除这个答案以防止其他人知道如何解决这个问题。祝你好运!

    我遇到了同样的问题和这篇文章 Set up mailing in redmine on heroku 解决了我的问题。

    想法是将设置从config/configuration.yml 移动到config/environments/production.rb,并使用Ruby 代码进行设置。由于ENV['key']erb 处理,我猜configuration.yml 不是这样处理的。也许有一些安全问题?

    所以在你的情况下,你应该将这些代码添加到config/environments/production.rb,如下所示,

    ActionMailer::Base.smtp_settings = {
      :address        => 'smtp.sendgrid.net',
      :port           => '587',
      :authentication => :plain,
      :user_name      => ENV['SENDGRID_USERNAME'],
      :password       => ENV['SENDGRID_PASSWORD'],
      :domain         => 'heroku.com'
    }
    ActionMailer::Base.delivery_method = :smtp
    

    并从config/configuration.yml 中删除代码并使其看起来像这样,

    default:
      # Outgoing emails configuration (see examples above)
      email_delivery:
        delivery_method: :smtp
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 2013-10-18
      • 2016-12-10
      • 2015-02-11
      • 2021-11-04
      • 1970-01-01
      相关资源
      最近更新 更多