简体   繁体   English

使用环境变量替换电子邮件配置

[英]Redmine email configuration with environment variables

I've configured email on redmine according to the instructions in the redmine wiki , and it all works fine. 我已经根据redmine Wiki中的说明在redmine上配置了电子邮件,并且一切正常。 Here are the contents of my config/configuration.yml file: 这是我的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 

However I am trying to use environment variables in place of my_email@gmail.com and my_password like so: 但是我试图使用环境变量代替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'] %>

When I try to send a test email, with the environment variables in the config file, redmine give this error: 当我尝试发送测试电子邮件时,在配置文件中包含环境变量,redmine会出现此错误:

'An error occurred while sending mail (535 Authentication failed: Bad username / password )'. “发送邮件时发生错误(535身份验证失败:用户名/密码错误)”。

So I guess the erb snippet is not being evaluated (I have double checked the values of the environment variables). 因此,我认为erb代码段没有被评估(我已经仔细检查了环境变量的值)。

I've searched for a solution and come up empty, does anyone have any suggestions as to how I should configure email in redmine so that I don't expose my sendgrid credentials in the config file? 我一直在寻找解决方案,却空无一人,有人对我应如何在Redmine中配置电子邮件以使我不会在配置文件中公开sendgrid凭据有任何建议吗?

Alternatively if someone can tell me that it's not a security risk to use the credentials directly, without environment variables, that would also solve my problem. 或者,如果有人可以告诉我没有环境变量而直接使用凭据没有安全风险,那也可以解决我的问题。

I had answered this question 2 weeks ago, and it was deleted by someone else right away. 我已经在2周前回答了这个问题,并且其他人立即将其删除。 So I'm not sure if someone will delete this answer again to prevent other guys knowing how to solve this problem. 因此,我不确定是否有人会再次删除此答案,以防止其他人知道如何解决此问题。 Good luck! 祝好运!

I got the same issue and this article Set up mailing in redmine on heroku solved my problem. 我遇到了同样的问题,这篇文章在heroku上的Redmine中设置邮件解决了我的问题。

The idea is moving the settings from config/configuration.yml to config/environments/production.rb and using Ruby code to set it up. 这个想法是将设置从config/configuration.yml移到config/environments/production.rb并使用Ruby代码进行设置。 Since ENV['key'] is handled by erb , I guess configuration.yml is not handled that way. 由于ENV['key']erb处理,所以我猜configuration.yml不是这样处理的。 Maybe there is some security issue? 也许有一些安全问题?

So in your case, you should add these codes to config/environments/production.rb as follows, 因此,在您的情况下,您应该将这些代码添加到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

And remove codes from config/configuration.yml and make it looks like this, 然后从config/configuration.yml删除代码,使其看起来像这样,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM