Joh*_*llo 1 email ruby-on-rails environment-variables redmine
我根据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
Run Code Online (Sandbox Code Playgroud)
但是我试图使用环境变量代替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'] %>
Run Code Online (Sandbox Code Playgroud)
当我尝试发送测试电子邮件时,配置文件中包含环境变量,redmine给出了以下错误:
'发送邮件时出错(535身份验证失败:用户名/密码错误)'.
所以我想erb片段没有被评估(我已经仔细检查了环境变量的值).
我已经搜索了一个解决方案并且空了,是否有人对如何在redmine中配置电子邮件有任何建议,以便我不在配置文件中公开我的sendgrid凭据?
或者,如果有人可以告诉我直接使用凭证不存在安全风险,没有环境变量,这也可以解决我的问题.
2个星期前我已经回答了这个问题,它是由别人马上删除.所以,我不知道是否有人会再次删除这个答案,以防止其他人知道如何解决这个问题.祝好运!
我有同样的问题和这篇文章 在heroku上设置redmine邮件解决了我的问题.
这个想法是从移动的设置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
Run Code Online (Sandbox Code Playgroud)
并从中删除代码config/configuration.yml并使其看起来像这样,
default:
# Outgoing emails configuration (see examples above)
email_delivery:
delivery_method: :smtp
Run Code Online (Sandbox Code Playgroud)