Search code examples
configurationyii2-advanced-appswiftmailer

Static Configuration for Switfmailer using yii2 won't send mails


using following static cofiguration will cause exception like this.

Swift_TransportException: Failed to authenticate on SMTP server with username "thomas.kipp@eisvogel-online-software.de" using 3 possible authenticators in

Using mail client will send mail without any problems,so following parameter basically are correct

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            'useFileTransport' => false, //set this property to true to send mails to mail emulator. Set this property to false to send real mails.              
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.strato.de',
                'username' => 'thomas.kipp@eisvogel-online-software.de',
                'password' => 'top secret',
                'port' => '587',
                'encryption' => 'tls',
            ],
        ],

What is wrong with this configuration? Following configuration:

     'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            'useFileTransport' => false, //set this property to true to send mails to mail emulator. Set this property to false to send real mails.              
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.gmail.com',
                'username' => 'tklustig.thomas@gmail.com',
                'password' => 'top secret',
                'port' => '587',
                'encryption' => 'tls',
            ],
        ],

will throw out error like this:

Swift_TransportException: Connection could not be established with host smtp.gmail.com [Connection timed out #145] in

Same thing with gmx. I am not able any more, sending mails using Swiftmailer. What could I do?


Solution

  • I think that google's smtp working on different port and encryption type.

    'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            'useFileTransport' => false,             
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.gmail.com',
                'username' => 'username',
                'password' => 'password',
                'port' => '465',
                'encryption' => 'ssl',
            ],
        ],
    

    I think this should solve your problem.

    btw. I can't figure out why your tls connection don't work. Try with ssl.