Symfony 5邮件程序:无法在SMTP上进行身份验证
我正试图通过以下方式使用Symfony 5.2上的新邮件程序。 我做了一个像这样的邮件控制器:Symfony 5邮件程序:无法在SMTP上进行身份验证,symfony,sendgrid,api-key,mailer,Symfony,Sendgrid,Api Key,Mailer,我正试图通过以下方式使用Symfony 5.2上的新邮件程序。 我做了一个像这样的邮件控制器: /** * @var EntityManagerInterface */ private $entityManager; /** * @var Swift_Mailer */ private $mailer; /** * MailingController constructor. * * @param EntityManagerInterface $entityManager *
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var Swift_Mailer
*/
private $mailer;
/**
* MailingController constructor.
*
* @param EntityManagerInterface $entityManager
* @param Swift_Mailer $mailer
*/
public function __construct(EntityManagerInterface $entityManager,
Swift_Mailer $mailer)
{
$this->mailer = $mailer;
$this->entityManager = $entityManager;
}
/**
* @Route("/email")
* @param MailerInterface $mailer
* @return Response
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
*/
public function sendEmail(MailerInterface $mailer): Response
{
$email = (new Email())
->from('hello@example.com')
->to('hello@example.com')
//->cc('cc@example.com')
//->bcc('bcc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Time for Symfony Mailer!')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
$mailer->send($email);
// ...
}
我被这个错误缠住了,我在网上到处都找过了,但是找不到任何可以消除这个错误的方法。我确实发现了问题,我将.env.local中的配置更改为:
###> symfony/sendgrid-mailer ###
SENDGRID_KEY=KEY
MAILER_DSN=sendgrid+smtp://$SENDGRID_KEY@default
###< symfony/sendgrid-mailer ###
###>symfony/sendgrid邮件###
SENDGRID_KEY=KEY
MAILER_DSN=sendgrid+smtp://$sendgrid_KEY@default
###
它现在工作得很好。感谢您的回答,但正如您所看到的,我没有使用swiftMailer依赖项,而是在函数sendEmail中使用MailerInterface。
Failed to authenticate on SMTP server with username "apikey" using the following authenticators: "LOGIN", "PLAIN". Authenticator "LOGIN" returned "Symfony\Component\Mailer\Exception\TransportException: Expected response code "235" but got code "451", with message "451 Authentication failed
###> symfony/sendgrid-mailer ###
SENDGRID_KEY=KEY
MAILER_DSN=sendgrid+smtp://$SENDGRID_KEY@default
###< symfony/sendgrid-mailer ###