How to use different email config for staging and production

phoenix
coherence
email
configuration

#1

How do you guyz maintain different configuration for dev, staging and production. Dev environment is straight forward. I use environment variable with “deferred_config” for most of the production and staging config and that mostly works. But in case of email I would like to use mailtrap config for dev and staging and mailgun for production. Any suggestion? I am using Coherence library.


#2

I would probably define a behaviour for the interface you’d like to use for sending email, and then implement that behaviour in a module that wraps Mailtrap, and in a module that wraps Mailgun.

Then in the project config, you can define which module should be used for sending mail, and their respective configurations.


#3

I’ll just use mailgun for staging. Its not really worth that affords since staging is using http auth anyway.


#4

Sorry if I misunderstood your question but can’t you use a different Mix.env for staging environment then use same configs as development for SMTP configs?

In your config.exs you can:

import_config "#{Mix.env}.exs"

Then create an staging.exs with:

use Mix.Config

config :your_app, :smtp_address, "your-mailtrap-config"

#5

I am using edeliver create releases so Mix.env is always prod when building a release. I don’t think there is any simple and straight forward way to add runtime config. I hope recent discussion will result in something to solve this problem.