8

i am getting this error when i try to send mails via sendgrid in laravel 6:

Failed to authenticate on SMTP server with username "apikey" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 250

my .env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=***** (my key copied from sendgrid)
MAIL_ENCRYPTION=tls
shape
  • 95
  • 2
  • 6

5 Answers5

2

I had this same problem and I solved it by encoding the APIKEY in Base64.

Here's a little more help: https://sendgrid.com/docs/API_Reference/SMTP_API/getting_started_smtp.html#-Sending-a-test-SMTP-email-with-Telnet

Ever CR
  • 351
  • 3
  • 7
  • Can you please let me know that which APIKEY you have encoded. When we login to sendgrid and go to the "Settings->Api Keys" Here we have an option for "Create Api Key", when we click on it ask for api key name. **So have you encode this name or some other field. ** Please let me know once you got the comment. – Manish Silawat Apr 30 '21 at 10:21
  • Encode your api key value in base64 and set like password – Ever CR Apr 30 '21 at 22:47
1

If you just recently edited your .env file, changes won't be applied to the config.

When running on php artisan serve, exit the server and restart it. The config should updated automatically.

I'm running xampp server on development, in my case I need to execute the following commands in the console to apply changes to config:

php artisan config:clear
php artisan config:cache

No need to change ports, my .env setup was the same:

MAIL_MAILER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=<your api key from sendgrid>
MAIL_ENCRYPTION=tls

I've omitted MAIL_FROM_ADDRESS and MAIL_FROM_NAME since my purpose is for our company's website contact form and I wanted the mail sender and email to be the guest or client email

If you are expecting to send from the same email all the time then populate those variables.

Here is an official documentation from sendgrid using Laravel mailables https://sendgrid.com/docs/for-developers/sending-email/laravel/

Dale Ryan
  • 473
  • 4
  • 9
1

Whitelisting my server's public IP address on SendGrid was all I needed in my case.

0

After spending 28 hours on this issue the solution is changing the port to 2525 and it's working now. You don't need to change or encode base64.

Using the following settings.

MAIL_MAILER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=2525
MAIL_USERNAME=apikey
MAIL_PASSWORD=sendgrid_apikey
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@example.com
MAIL_FROM_NAME="${APP_NAME}"
0

I had this same problem and I found issue.

Mailgun temporarily disabled my account due to pending monthly invoice payment.that's why i was receiving that error.

So, you should check once your mail service/account status.