2013-02-23 94 views
1

我已经根据redmine wiki中的说明在redmine上配置了电子邮件,并且它一切正常。下面是我的配置/ configuration.yml文件的内容:带环境变量的Redmine电子邮件配置

production: 
delivery_method: :smtp 
smtp_settings: 
    address: "smtp.sendgrid.net" 
    port: 587 
    authentication: :plain 
    domain: "heroku.com" 
    user_name: [email protected] 
    password: my_password 

不过,我想使用环境变量来代替[email protected]和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'] %> 

当我尝试发送测试电子邮件,在配置文件中的环境变量,管理平台给这个错误:

'An error occurred while sending mail (535 Authentication failed: Bad username/password)'.

所以我想ERB片段不被评价(我有双重检查日环境变量的值)。

我已经搜索了一个解决方案,并提出空,有没有人有任何建议,我应该如何在redmine配置电子邮件,以便我不公开我配置文件中的sendgrid凭据?

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

回答

6

我在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