How to use different email config for staging and production

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.

1 Like

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.


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

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"

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.