我已根据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片段没有被评估(我已经仔细检查了环境变量的值)。
我已经搜索了一个解决方案并且空了,是否有人对如何在redmine中配置电子邮件有任何建议,以便我不在配置文件中公开我的sendgrid凭据?
或者,如果有人可以告诉我直接使用凭证不存在安全风险,没有环境变量,这也可以解决我的问题。
答案 0 :(得分: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