yii2 - Send email by console use transport
<p>I want send email by console with Swift_SmtpTransport. </p>

<p>The same transport settings work in common/config/main-local.php and don't work in console/config/main-local.php.</p>

<p>In console in config/main-local.php I have:</p>

<pre><code>&lt;?php
return [
    'components' =&gt; [        
        'mail' =&gt; [
            'class' =&gt; 'yii\swiftmailer\Mailer',
            'viewPath' =&gt; '@common/mail',
            'htmlLayout' =&gt; '@common/mail/layouts/html',
            'textLayout' =&gt; '@common/mail/layouts/text',  // custome layout        
            'transport' =&gt; [
                'class' =&gt; 'Swift_SmtpTransport',
                'host' =&gt; 'gator.hostgator.com',
                'username' =&gt; 'test@pix.com',
                'password' =&gt; '*******',
                'port' =&gt; '465',
                'encryption' =&gt; 'ssl',
            ],
        ],
    ],    
];
</code></pre>

<p>With this configuration (and in common the settings are the same and work) I load the script by command and no email send and no error.</p>

<p>With this (I delete the transport settings) I run the same script by command and the email send ok:</p>

<pre><code>&lt;?php
return [
    'components' =&gt; [        
        'mail' =&gt; [
            'class' =&gt; 'yii\swiftmailer\Mailer',
            'viewPath' =&gt; '@common/mail',
            'htmlLayout' =&gt; '@common/mail/layouts/html',
            'textLayout' =&gt; '@common/mail/layouts/text',  // custome layout        
        ],
    ],    
];
</code></pre>

<p>In console/controllers/CronController I have this:</p>

<pre><code>&lt;?php

namespace console\controllers;

use yii\console\Controller;
use backend\models\Definicoes;
use common\models\Acordo;
use Yii;

/**
 * Cron controller
 */
class CronController extends Controller {

    public function actionIndex() {
        $data_hoje = date('Y-m-d');
        $model_definicoes = Definicoes::find()-&gt;one();

        Yii::$app-&gt;mail-&gt;compose('@common/mail/cron_acordo', ['model_definicoes' =&gt; $model_definicoes])
           -&gt;setFrom([Yii::$app-&gt;params['adminEmail'] =&gt; Yii::$app-&gt;params['nome']])
           -&gt;setSubject('Alert')
           -&gt;setTo('ideinto@gmail.com')     
           -&gt;send();        
    }
}
</code></pre>

<p>Why this happen? I can´t use transport in console?</p>

<p>Thanks!</p>