HowTo set and access Mailer configuration on anynines

In order to avoid adding sensitive password information of your mail server to your source code, you should consider reading out those information from the environment. You can simply add environment variables inside of the manifest.yml under ‘env’ as shown below:

- name: videoapp
memory: 350M
instances: 3
path: .
- my-mongodb
- objectstore
RAILS_ENV: production
EMAIL_PASSWORD: 'very secure password'

Those variables will be available under ENV[‘your variable name’] and can be used in this way to load the EMAIL_USERNAME and EMAIL_PASSWORD from the environment.

config.action_mailer.smtp_settings = {
:address => "",
:port => 587,
:user_name => ENV['EMAIL_USERNAME'],
:password => ENV['EMAIL_PASSWORD'],
:authentication => :login,
:enable_starttls_auto => true

If you use other languages, the way the language reads env variables is different, which is obvious. Let’s say in nodejs for example, you access Environment variables with process.env. Java uses System.getEnv.

You can see the environment variables defined this way with the CF cli running the command: cf env. You will find those variables under the title User-Provided. For this Manifest, they will look like this:

EMAIL_PASSWORD: very secure password
RAILS_ENV: production
STACK: cedar

Leave a Reply

Your email address will not be published. Required fields are marked *