<p>I think you're getting a few conventions mixed up.</p>

<p>Using an <code>@</code> is typically reserved for aliases <a href="https://docs.craftcms.com/v3/config/environments.html#using-aliases-in-control-panel-settings" rel="nofollow noreferrer">https://docs.craftcms.com/v3/config/environments.html#using-aliases-in-control-panel-settings</a></p>

<p>What you're probably looking for is environment variables in your .env file.</p>

<p>You could set:</p>

<pre><code>EMAIL_HOST=myhost
EMAIL_PORT=myport
EMAIL_USERNAME=myusername
EMAIL_PASSWORD=mypassword
</code></pre>

<p>Then from Settings->Email in the control panel, you can reference them with <code>$</code> <a href="https://docs.craftcms.com/v3/config/environments.html#control-panel-settings" rel="nofollow noreferrer">https://docs.craftcms.com/v3/config/environments.html#control-panel-settings</a></p>

<pre><code>$EMAIL_HOST
$EMAIL_PORT
$EMAIL_USERNAME
$EMAIL_PASSWORD
</code></pre>

CC BY-SA 4.0
2020-04-26T03:18:44.507Z
2020-04-26T03:18:44.507Z
Brad Bell
<p>I'm trying to create an environment variable for email settings, but it doesn't work. Here is my email setting at config/general.php</p>

<pre><code>'dev' =&gt; [
    '@host' =&gt; 'host',
    '@port' =&gt; '587',
    '@username' =&gt; 'user@user',
    '@password' =&gt; 'passwrod'
],
</code></pre>

<p><a href="https://i.sstatic.net/MYpuU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MYpuU.png" alt="This is my email setting"></a></p>

<p>I have also tried before to configure the email setting using this way at config/app.php, but it doesn't work.</p>

<pre><code>'components' =&gt; [
    'mailer' =&gt; function() {
        // Get the stored email settings
        $settings = Craft::$app-&gt;systemSettings-&gt;getEmailSettings();

        // Override the transport adapter class
        $settings-&gt;transportType = \craft\mail\transportadapters\Smtp::class;

        // Override the transport adapter settings
        $settings-&gt;transportSettings = [
            'host' =&gt; 'host',
            'port' =&gt; '587',
            'useAuthentication' =&gt; true,
            'username' =&gt; 'user@user',
            'password' =&gt; 'passwrod'
        ];

        return craft\helpers\MailerHelper::createMailer($settings);
    }
]
</code></pre>

<p>Am I doing anything wrong?</p>

<config><emails><variable><environmentvariables><configuration>
Error using environment variable for email setting
# Error using environment variable for email setting

(Asked by: username_0 on 2020-04-25)

I'm trying to create an environment variable for email settings, but it doesn't work. Here is my email setting at config/general.php
'dev' => [
    '@host' => 'host',
    '@port' => '587',
    '@username' => 'user@user',
    '@password' => 'passwrod'
],


I have also tried before to configure the email setting using this way at config/app.php, but it doesn't work.
'components' => [
    'mailer' => function() {
        // Get the stored email settings
        $settings = Craft::$app->systemSettings->getEmailSettings();

        // Override the transport adapter class
        $settings->transportType = \craft\mail\transportadapters\Smtp::class;

        // Override the transport adapter settings
        $settings->transportSettings = [
            'host' => 'host',
            'port' => '587',
            'useAuthentication' => true,
            'username' => 'user@user',
            'password' => 'passwrod'
        ];

        return craft\helpers\MailerHelper::createMailer($settings);
    }
]

Am I doing anything wrong?

**Tags:** config, emails, variable, environmentvariables, configuration


---

## 1 answers

### Answer by username_1 on 2020-04-26. Score: 1 | Accepted answer

I think you're getting a few conventions mixed up.
Using an @ is typically reserved for aliases https://docs.craftcms.com/v3/config/environments.html#using-aliases-in-control-panel-settings
What you're probably looking for is environment variables in your .env file.
You could set:
EMAIL_HOST=myhost
EMAIL_PORT=myport
EMAIL_USERNAME=myusername
EMAIL_PASSWORD=mypassword

Then from Settings->Email in the control panel, you can reference them with $ https://docs.craftcms.com/v3/config/environments.html#control-panel-settings
$EMAIL_HOST
$EMAIL_PORT
$EMAIL_USERNAME
$EMAIL_PASSWORD


---

