0
votes

I wrote an application in symfony 4. I deployed it on the heroku. Everything works as it should with the exception of sending emails. When I trying to send an e-mail from the console like this:

heroku run php bin/console swiftmailer:email:Send

Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "[email protected]" using 1 possible authenticat ors. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 Please log in via your web browser and then try again. Learn more at https://support.google.com/mail/answer/78754 i65sm11848023qkh.49 - gsmtp " in /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457

This is my swiftmailer.yaml file:

swiftmailer: transport: gmail username: username password: ******** host: localhost port: 465 encryption: ssl auth-mode: login spool: { type: 'memory' } stream_options: ssl: allow_self_signed: true verify_peer: false verify_peer_name: false

How to fix this error?

1
Gmail need specific configuration (symfony doc). Are you sure it is not smtp you need to use as transport ?Pouette
I try it but it doesnt work. I also changed host to smtp.gmail.com. But still get the same error.Major Kuprich

1 Answers

0
votes

The problem is in Gmail. Although I have set up security to allow less secure applications and e-mails from local hosts are sent correctly when I perform the same operation in gmail heroku, I see a new device - unfortunately I can't add it to trusted devices, therefore it's blocked.

The solution was to change mail, e.g. on yandex.com. Here is an example file swiftmailer.yaml correctly configured for heroku:

swiftmailer:
  transport:        smtp
  username:         username
  password:         ********
  host:             smtp.yandex.com
  port:             465
  encryption:       ssl
  auth-mode:        login
  spool: { type: 'memory' }
  stream_options:
    ssl:
      allow_self_signed: true
      verify_peer: false
      verify_peer_name: false