<p>If you're running Craft 3.7.22 or later, all SMTP-related email settings (except &quot;Timeout&quot;) support environment variables.</p>
<p>Most SMTP related settings received environment variable support in Craft 3.1.0, excluding &quot;Use authentication&quot; and &quot;Encryption Method&quot; which only supports environment variables since Craft 3.7.22.</p>

CC BY-SA 4.0
2021-12-22T23:24:27.310Z
2021-12-22T23:24:27.310Z
Mats Mikkel Rummelhoff
<p>Not an easy way to do this in Craft 2, but this is possible in the upcomgin Craft 3 (currently in beta) using <a href="https://github.com/craftcms/docs/blob/master/en/configuration.md#application-config" rel="nofollow noreferrer"><code>craft/config/app.php</code></a>, which is multi-environment aware. </p>

CC BY-SA 3.0
2017-04-04T00:13:06.527Z
2017-04-04T00:13:06.527Z
Brad Bell
<p>Pretty straight forward here, I'd like to use MailTrap for <code>devMode</code> and then use an SMTP service (Mandrill or like) for production. I looked through the <a href="https://craftcms.com/docs/config-settings" rel="noreferrer">General Config Settings</a> docs but didn't see anything that lent itself to being SMTP related. Is this possible?</p>

CC BY-SA 3.0
2017-08-02T20:35:44.900Z
Shameless plug: We've written a plugin that automatically updates your email settings depending on your environment. It's not free, but it is cheap :-) Please [check out](http://red-robot.co.uk/our-work/email-settings-craft-cms-plug-in) the page on our website for more information.
Gaz
<config><emails><settings>
Can I set an environment var for SMTP mail servers?
# Can I set an environment var for SMTP mail servers?

(Asked by: username_0 on 2017-04-04)

Pretty straight forward here, I'd like to use MailTrap for `devMode` and then use an SMTP service (Mandrill or like) for production. I looked through the [General Config Settings](https://craftcms.com/docs/config-settings) docs but didn't see anything that lent itself to being SMTP related. Is this possible?

**Tags:** config, emails, settings

> **Comments:**
> **username_1**: Shameless plug: We've written a plugin that automatically updates your email settings depending on your environment. It's not free, but it is cheap :-) Please [check out](http://red-robot.co.uk/our-work/email-settings-craft-cms-plug-in) the page on our website for more information.  

---

## 2 answers

### Answer by username_3 on 2017-04-04. Score: 4 | Accepted answer

Not an easy way to do this in Craft 2, but this is possible in the upcomgin Craft 3 (currently in beta) using [`craft/config/app.php`](https://github.com/craftcms/docs/blob/master/en/configuration.md#application-config), which is multi-environment aware.


---

### Answer by username_2 on 2021-12-22. Score: 2

If you're running Craft 3.7.22 or later, all SMTP-related email settings (except "Timeout") support environment variables.

Most SMTP related settings received environment variable support in Craft 3.1.0, excluding "Use authentication" and "Encryption Method" which only supports environment variables since Craft 3.7.22.


---

