laravelsendgrid

How to solve the Sendgrid STMP Error 250 response in Laravel


I am using Sendgrid for the mail service.

My Account is two factor authentication is enabled.

My .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=S4gYKuoPRBaOAy7qT__J8w
MAIL_PASSWORD=SG.APIKEYPASSWORD
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Xyz Name"
MAIL_FROM_ADDRESS=xyz@xyz.com

If I execute the mail then I am getting below error.

Swift_TransportException : Failed to authenticate on SMTP server with username "S4gYKuoPRBaOAy7qT__J8w" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 250 but got an empty response. Authenticator PLAIN returned Expected response code 250 but got an empty response.

And If I disable the two-factor authentication then it works with the UserName and Password of the account but sendgrid will suspend my account if I do it like this.

Can anyone faced this issue. if yes then please let me know how you solved the problem.


Solution

  • Try using the literal value 'apikey' as the MAIL_USERNAME, and the key from an API Key that you create in Settings >> API Keys as the MAIL_PASSWORD.

    They are now enforcing 2FA, and auth with keys instead of a user/password when using 2FA, starting Nov 18, 2020. I just changed over and this worked for me.

    For example,

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.sendgrid.net
    MAIL_PORT=587
    MAIL_USERNAME=apikey
    MAIL_PASSWORD=SG.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx