Search code examples
phpamazon-web-servicesyii2amazon-sessymfony-mailer

Yii2 Symfony mailer not working with AWS SES


Recently I migrated my application mailer from Swiftmailer to Symfony due to deprecation notification from Yii.
I use AWS SES services to send email through SMTP, which was working perfectly with Swiftmailer but after migration, no mails are received but the function returns true.
I followed this method to install the mailer. Sharing my codes for better understanding.

config/main-local.php.

$password = 'MY_AWS_SES_PASSWORD';
$password = urlencode($password);
'mailer' => [
        'class' => \yii\symfonymailer\Mailer::class,
        'transport' => [
            'scheme' => 'smtps',
            'host' => 'email-smtp.ap-south-1.amazonaws.com',
            'username' => 'MY_AWS_SES_USERNAME',
            'password' => $password,
            'port' => '465',
            'dsn' => 'sendmail://default',
        ],
        'viewPath' => '@common/mail',
        // send all mails to a file by default. You have to set
        // 'useFileTransport' to false and configure transport
        // for the mailer to send real emails.
        'useFileTransport' => false,
    ],  

Sample Mail Function.

    public function actionMail()
{
    return Yii::$app
        ->mailer
        ->compose()
        ->setFrom(Yii::$app->params['adminEmail')
        ->setTo($model->to_email)
        ->setSubject('Account registration at ' . Yii::$app->name)
        ->setTextBody($messages)
        ->send();
}. 

Can any one help me what I am missing on the configuration?


Solution

  • Thank you for the supports, it was due to the DNS, found the solution, sharing for the future references..

    $password = 'MY_AWS_SES_SMTP_PWD';
    $password = urlencode($password);
        'mailer' => [
                'class' => \yii\symfonymailer\Mailer::class,
                'transport' => [
                    'dsn' => 'ses+smtp://MY_AWS_SES_SMTP_USERNAME:' . $password . '@default?region=ap-south-1',
                ],
                'viewPath' => '@common/mail',
                // send all mails to a file by default. You have to set
                // 'useFileTransport' to false and configure transport
                // for the mailer to send real emails.
                'useFileTransport' => false,
            ],  
    

    Please make sure you install symfony amazon-mailer using below command.

    composer require symfony/amazon-mailer. 
    

    Detailed documentation is available on this link.