Unable to send email using sendgrid and strapi getting 500 error

System Information
  • 4:
  • Operating System:
  • SqlLite:
  • Node Version:
  • NPM Version:
  • Yarn Version:

I am getting the below error when i try to send an email please help Sendgrid key is inside the plugins.js

Hello my email is: {
  to: 'vini@vidyori.com',
  subject: 'Strapi test mail to: vini@vidyori.com',
  text: 'Great! You have correctly configured the Strapi email plugin with the sendgrid provider. \r\n' +
    'For documentation on how to use the email plugin checkout: https://docs.strapi.io/developer-docs/latest/plugins/email.html'
}
[2023-12-14 16:13:52.690] error: Couldn't send test email: Unauthorized.
Error: Couldn't send test email: Unauthorized.
    at Object.test (/Users/vinikatyal/Documents/projects/gg-strapi/node_modules/@strapi/plugin-email/server/controllers/email.js:55:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async returnBodyMiddleware (/Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
    at async policiesMiddleware (/Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
    at async /Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/@strapi/strapi/lib/middlewares/body.js:58:9
    at async /Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/@strapi/strapi/lib/middlewares/logger.js:9:5
    at async /Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
    at async cors (/Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/@koa/cors/index.js:107:16)
    at async /Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
    at async session (/Users/vinikatyal/Documents/projects/globeia-strapi/node_modules/koa-session/index.js:41:7)

Hey Vini,

Did you verify your sendgrid key is valid? Also verify if your config looks like the below in plugins.js

email: {
    config: {
      provider: 'sendgrid',
      providerOptions: {
        apiKey: env('SENDGRID_API_KEY'),
      },
      settings: {
        defaultFrom: 'hello@email.com',
        defaultReplyTo: 'hello@email.com',
      },
    },
  }

Hey it worked my bad was a stupid mistake

Great
Happy coding :slight_smile:

1 Like

@Shekhar thank you for your help.