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:

[code light=”false” language=”python”]
#manifest.yml

applications:
– name: videoapp
memory: 350M
instances: 3
buildpack: https://github.com/cloudfoundry/ruby-buildpack#v1.4.2
domain: de.a9sapp.eu
path: .
services:
– my-mongodb
– objectstore
env:
RAILS_ENV: production
EMAIL_USERNAME: noreply@anynines.com
EMAIL_PASSWORD: ‘very secure password’
[/code]

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.

[code light=”false” language=”ruby”]
#production.rb
config.action_mailer.smtp_settings = {
:address => “mail.anynines.com”,
:port => 587,
:user_name => ENV[‘EMAIL_USERNAME’],
:password => ENV[‘EMAIL_PASSWORD’],
:authentication => :login,
:enable_starttls_auto => true
}
[/code]

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:

[code light=”false” language=”bash”]
User-Provided:
EMAIL_PASSWORD: very secure password
EMAIL_USERNAME: noreply@anynines.com
RAILS_ENV: production
STACK: cedar
[/code]

Leave a Reply

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