Sending mail from front-end using sendgrid api

Am using sendGrid (https://api.sendgrid.com/v3/mail/send) to send mail from frontEnd.
but getting the CORS error. To fix this issue I tried to add following code in headers, but not get fixed:
‘Access-Control-Allow-Origin’: ‘https://sendgrid.com’,
‘Access-Control-Allow-Methods’: ‘POST, GET, OPTIONS’,
‘Access-Control-Allow-Headers’:‘X-Requested-With’,
“Accept-Encoding”:“gzip, deflate, br”,
“Accept”: “/”,

So I need help here to fix this cors issue , so that I can use sendgrid API to send mail from front-end.

Hi,

SendGrid does not allow you to use their endpoints directly from a frontend application.
You need to create a backend service which does the actual request to SendGrid.

This could have been found with a quick google search e.g. here: node.js - Nodejs SendGrid CORS request blocked - Stack Overflow

1 Like

Thanks for the reply.
So do we have any predefined backend service in cumulocity, to use sendGrid endpoint?

You need to implement your own (small) microservice that integrates the sendGrid API. I’m not aware of an existing microservice just doing that…
As an alternative you can use webMethods.io to integrate sendGrid and trigger sending email via Events or directly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.