0

I don't want to put the account and password for our gmail account in the production app config file.

Rather I would like to set things up so that this information is in a separate yml file that will not be stored on our git repository. We do this with other data that needs to be secured, but I don't see a straight forward way to do it with action_mailer.

In otherwords I want action_mailer to read its config info from something like action_mailer_config.yml NOT from the environments/production.rb config file.

4

3 回答 3

0

Just create an initializer file that assigns an environmental variable. So in your production environment you would have:

   config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: "chicheng.com.tw",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: ENV["GMAIL_USERNAME"],
    password: ENV["GMAIL_PASSWORD"],
    :openssl_verify_mode  => 'none'
    }

Then you add an initializer file that assigns the username and password like this:

ENV["GMAIL_USERNAME"] = "your_username@gmail.com"
ENV["GMAIL_PASSWORD"] = "your_password"

One important thing to remember is that you add this initializer file to your git ignore. You would then need to manually make sure this file is included when you push it up.

To be honest instead of using a separate file, I prefer just setting the ENV on the server directly. This way I do not have to worry about the file accidentally getting pushed.

于 2012-10-22T18:23:49.660 回答
0

最近在 railscasts 中涵盖了此要求。http://railscasts.com/episodes/85-yaml-configuration-revised

确保检查替代宝石的评论。

于 2012-10-22T17:24:45.470 回答
0

这是一个较老的问题,因此您可能已经有了答案,但我使用 Heroku 进行了部署,它们允许您从其 cli 设置配置变量(如 ENV)。值得检查您的提供程序是否允许类似的实现。它让事情变得容易多了。 是一篇有更好解释的文章。

于 2014-02-19T00:56:03.060 回答