通过 aws ses 从 symfony 邮件程序发送电子邮件时出错

dos*_*sad 6 php amazon-web-services symfony amazon-ses symfony-mailer

我的适合发送电子邮件的控制器如下所示:

class MailerController extends AbstractController
{
    /**
     * @Route("/email")
     */
    public function sendEmail(MailerInterface $mailer): Response
    {
        $email = (new Email())
            ->from('hello@example.com')
            ->to('you@example.com')
            ->subject('Time for Symfony Mailer!')
            ->text('Sending emails is fun again!')

        $mailer->send($email);

        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

访问后/email我收到以下错误:

Failed to authenticate on SMTP server with username "XXX" using the following authenticators: "LOGIN", "PLAIN". Authenticator "LOGIN" returned "Symfony\Component\Mailer\Exception\TransportException: Expected response code "235" but got code "535", with message "535 Authentication Credentials Invalid"
Run Code Online (Sandbox Code Playgroud)

我的邮件程序配置如下所示:

Failed to authenticate on SMTP server with username "XXX" using the following authenticators: "LOGIN", "PLAIN". Authenticator "LOGIN" returned "Symfony\Component\Mailer\Exception\TransportException: Expected response code "235" but got code "535", with message "535 Authentication Credentials Invalid"
Run Code Online (Sandbox Code Playgroud)

我想补充一点,我XXX和YYY是从 这里获得的AWS凭证

小智 3

您可以通过安装新的库composer require symfony/amazon-mailer并使用来修复它ses+api

但请确保对密钥中的任何特殊字符进行 urlencode。

例子:

ses+smtp://$AWS_MAILER_USER:$WS_MAILER_PASSWORD@default?region=eu-west-1
Run Code Online (Sandbox Code Playgroud)

另一种选择是尝试使用async-aws/ses包。