# Sending mail from front-end using sendgrid api

**URL:** <https://community.cumulocity.com/t/sending-mail-from-front-end-using-sendgrid-api/6233>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [August 30, 2023, 7:49am UTC](https://community.cumulocity.com/t/sending-mail-from-front-end-using-sendgrid-api/6233 "2023-08-30T07:49:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rapatel](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rapatel](https://community.cumulocity.com/u/rapatel)\
**Post date:** [August 30, 2023, 7:49am UTC](https://community.cumulocity.com/t/sending-mail-from-front-end-using-sendgrid-api/6233/1 "2023-08-30T07:49:08Z")

</div>

Am using sendGrid ([https://api.sendgrid.com/v3/mail/send](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](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.

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [August 30, 2023, 7:57am UTC](https://community.cumulocity.com/t/sending-mail-from-front-end-using-sendgrid-api/6233/2 "2023-08-30T07:57:26Z")

</div>

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](https://stackoverflow.com/a/65723943)

---

<div class="post-metadata">

**Author:** ![rapatel](https://avatars.discourse-cdn.com/v4/letter/r/c6cbf5/32.png) [@rapatel](https://community.cumulocity.com/u/rapatel)\
**Post date:** [August 31, 2023, 6:47am UTC](https://community.cumulocity.com/t/sending-mail-from-front-end-using-sendgrid-api/6233/3 "2023-08-31T06:47:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [August 31, 2023, 9:14am UTC](https://community.cumulocity.com/t/sending-mail-from-front-end-using-sendgrid-api/6233/4 "2023-08-31T09:14:20Z")

</div>

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](http://webMethods.io) to integrate sendGrid and trigger sending email via Events or directly.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [March 2, 2024, 12:15pm UTC](https://community.cumulocity.com/t/sending-mail-from-front-end-using-sendgrid-api/6233/6 "2024-03-02T12:15:45Z")

</div>

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