英文:
Yii2 Symfony mailer not working with AWS SES
问题
Recently I migrated my application mailer from Swiftmailer
to Symfony
due to deprecation notification from Yii.
我最近将我的应用程序邮件发送器从Swiftmailer
迁移到Symfony
,因为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
.
我使用AWS SES
服务通过SMTP发送电子邮件,与Swiftmailer一起完美运行,但迁移后,不再接收邮件,但函数返回true
。
I followed this method to install the mailer. Sharing my codes for better understanding.
我按照此方法安装邮件发送器。分享我的代码以更好地理解。
config/main-local.php.
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?
有人可以帮助我看看我在配置中漏掉了什么吗?
英文:
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?
答案1
得分: 2
谢谢您的支持,问题出在 DNS 上,找到了解决方法,分享给未来的参考。
$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',
'useFileTransport' => false,
],
请确保您使用以下命令安装 Symfony Amazon Mailer。
composer require symfony/amazon-mailer
详细文档请参考此链接。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论