Redmine电子邮件配置与环境变量 [英] Redmine email configuration with environment variables
问题描述
我已根据redmine wiki ,一切正常。以下是我的config / configuration.yml文件的内容:
production:
delivery_method::smtp
smtp_settings:
地址:smtp.sendgrid.net
端口:587
身份验证::plain
域:heroku.com
user_name:my_email @ gmail.com
密码:my_password
但是我试图使用环境变量代替my_email@gmail.com和my_password如下:
production:
delivery_method::smtp
smtp_settings:
地址:smtp.sendgrid.net
端口:587
身份验证::plain
域:heroku.com
user_name:<%= ENV ['SENDGRID_USERNAME']%>
密码:<%= ENV ['SENDGRID_PASSWORD']%>
当我尝试发送测试电子邮件,配置文件中的环境变量,redmine给这个错误:
发送邮件时发生错误(535验证失败:用户名/密码不正确)'
所以我猜Erb片段没有被评估(我已经仔细检查了环境变量的值)。
我已经搜索了一个解决方案,并提出了空白,有没有人有任何建议,我应该如何配置电子邮件在redmine,以便我不暴露我的sendgrid凭据在配置文件中?或者如果有人可以告诉我,直接使用凭据并没有安全风险,没有环境变量,这也会解决我的问题。
2周前我已经回答了这个问题,并立即被其他人删除。
所以我不知道有人会再次删除这个答案,以防止其他人知道如何解决这个问题。祝你好运!
我有同样的问题,这篇文章
设置邮件在redmine在英雄解决了我的问题。
想法是从配置/ config.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
中删除代码,使其看起来像这样,
code>默认值:
#发送电子邮件配置(参见上面的示例)
email_delivery:
delivery_method::smtp
I've configured email on redmine according to the instructions in the redmine wiki, and it all works fine. Here are the contents of my config/configuration.yml file:
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:
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:
'An error occurred while sending mail (535 Authentication failed: Bad username / password )'.
So I guess the erb snippet is not being evaluated (I have double checked the values of the environment variables).
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?
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. 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.
The idea is moving the settings from config/configuration.yml
to config/environments/production.rb
and using Ruby code to set it up. Since ENV['key']
is handled by erb
, I guess configuration.yml
is not handled that way. Maybe there is some security issue?
So in your case, you should add these codes to config/environments/production.rb
as follows,
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,
default:
# Outgoing emails configuration (see examples above)
email_delivery:
delivery_method: :smtp
这篇关于Redmine电子邮件配置与环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!