<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Firebase Cloud function to send emails via SendGrid]]></title><description><![CDATA[<p dir="auto">In this post i'm showing you how to send emails via firebase cloud functions by <strong>SendGrid</strong>. SendGrid is a cloud based email service it has free tier which will help you to begin. Also we have to enable firebase billing to work this correctly, because firebase free plan only allow google services for outbound networking.</p>
<p dir="auto">For this tutorial i'm assuming you have installed firebase sdk and log into your firebase account.</p>
<p dir="auto"><strong>Setting up things</strong></p>
<ol>
<li>Open terminal &amp; run <code>firebase init</code> to initilize firebase functions</li>
<li>We need two packages for this, add them via npm
<ol>
<li><code>npm install @sendgrid/mail</code></li>
<li><code>npm install cors</code></li>
</ol>
</li>
<li>Now open <strong>index.js</strong> and put below code.</li>
</ol>
<pre><code>const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp();

const SENDGRID_API_KEY = "PUT_YOUR_SENDGRID_API_KEY";

const sgMail = require('@sendgrid/mail');
const cors = require("cors")({
  origin: true
});

exports.sendEmail = functions.https.onRequest((req, res) =&gt; {
	return cors(req, res, () =&gt; {
  	const msg = {
      to: req.body.email,
      from: 'hi@somedomain.com',
      subject:  'SUBJECT',
      templateId: 'd-02d153b9f48f490bb73bfcc6ad92d892', //SendGrid Template ID
      // SendGrid Template Variables
      dynamic_template_data: {
        name: req.body.name,
        event_name: req.body.event,
        date: req.body.date
      }
    };
    
    sgMail.send(msg).then(res =&gt; {
      res.send({
        success: true,
        message: res
      });
    }).catch(err =&gt; {
      res.send({
        success: false,
        error: err
      });
    });
  });
});
</code></pre>
<ol start="4">
<li>Now deploy our function by running <code>firebase deploy --only functions</code></li>
</ol>
<p dir="auto"><strong>NOTE - To work this correctly, you must enable billing on your firebase account</strong></p>
]]></description><link>https://lankadevelopers.lk/topic/546/firebase-cloud-function-to-send-emails-via-sendgrid</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 16:35:23 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/546.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Apr 2020 08:01:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Firebase Cloud function to send emails via SendGrid on Mon, 06 Apr 2020 08:35:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/27">@root</a> @cody  welcome bro</p>
]]></description><link>https://lankadevelopers.lk/post/3245</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3245</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Mon, 06 Apr 2020 08:35:56 GMT</pubDate></item><item><title><![CDATA[Reply to Firebase Cloud function to send emails via SendGrid on Mon, 06 Apr 2020 06:25:25 GMT]]></title><description><![CDATA[<p dir="auto">thanks bro</p>
]]></description><link>https://lankadevelopers.lk/post/3244</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3244</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Mon, 06 Apr 2020 06:25:25 GMT</pubDate></item><item><title><![CDATA[Reply to Firebase Cloud function to send emails via SendGrid on Sat, 04 Apr 2020 22:16:20 GMT]]></title><description><![CDATA[<p dir="auto">great bro</p>
]]></description><link>https://lankadevelopers.lk/post/3240</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3240</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Sat, 04 Apr 2020 22:16:20 GMT</pubDate></item><item><title><![CDATA[Reply to Firebase Cloud function to send emails via SendGrid on Sat, 04 Apr 2020 08:13:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/99">@Sahan-Pasindu-Nirmal</a> said in <a href="/post/3236">Firebase Cloud function to send emails via SendGrid</a>:</p>
<blockquote>
<p dir="auto">ස්තුතියි. onCreate වගේ වෙන එකක්ද functions.https.onRequest කියන්නේ?</p>
</blockquote>
<p dir="auto">ow, https.onRequest kyanne http request ekak awama execute wena method ekak</p>
]]></description><link>https://lankadevelopers.lk/post/3237</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3237</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Sat, 04 Apr 2020 08:13:32 GMT</pubDate></item><item><title><![CDATA[Reply to Firebase Cloud function to send emails via SendGrid on Sat, 04 Apr 2020 08:11:44 GMT]]></title><description><![CDATA[<p dir="auto">ස්තුතියි. onCreate වගේ වෙන එකක්ද functions.https.onRequest කියන්නේ?</p>
]]></description><link>https://lankadevelopers.lk/post/3236</link><guid isPermaLink="true">https://lankadevelopers.lk/post/3236</guid><dc:creator><![CDATA[Sahan Pasindu Nirmal]]></dc:creator><pubDate>Sat, 04 Apr 2020 08:11:44 GMT</pubDate></item></channel></rss>