title: sendGrid + firebase cloud functions: Email is not sending with Callable functions
body: <p>I'm new to javascript and I'm trying to send email with the firebase callable functions. the idea is to send code to user email from a cloud function when called from the iOS app. But the thing is, functions can be deployed but I'm not sure what is wrong with my code as it is not sending the email. I have already configure the Sendgrid api key and template id so it doesn't seems like the issue here. Plus the functions log on firebase is not returning any Error. Can someone help? here's my code</p>
  <p><strong>Cloud Function code:</strong></p>
  <pre><code>const functions = require(&quot;firebase-functions&quot;);
  
  const admin = require(&quot;firebase-admin&quot;);
  admin.initializeApp();
  
  const db = admin.firestore();
  
  const sgMail = require(&quot;@sendgrid/mail&quot;);
  const SENDGRID_API_KEY = functions.config().sendgrid.key;
  const TEMPLATE_ID = functions.config().sendgrid.template;
  sgMail.setApiKey(SENDGRID_API_KEY);
  
  exports.requestTurn = functions.https.onCall((data, context) =&gt; {
    const uid = context.auth.uid;
    console.log(&quot;UID: &quot; + uid);
    const email = context.auth.token.email;
    console.log(&quot;Name: &quot; + email);
  
    const send = &quot;Here is your query number!&quot;;
  
    const docRef = db.collection(&quot;Users&quot;).doc(uid);
    const code = docRef.set({&quot;sentEmail&quot;: send}, {merge: true});
  
    const msg = {
       to: email,
       from: &quot;myemailaddress&quot;,
       templateId: TEMPLATE_ID,
       dynamic_template_data: {
          subject: &quot;Welcome&quot;,
          CODE: send,
       }
    };
  
    const res = db.collection(&quot;mail&quot;).doc().set(msg);
  
    console.log(&quot;email saved to Firestore!&quot;);
    return sgMail.send(msg);
    // return {
    //   message: text,
    //   code,
    // };
  })
  </code></pre>
  <p><strong>and this is how I call it from swiftui app:</strong></p>
  <pre><code>func requestTurn(){
          let data = [&quot;Hello!&quot;]
          
          functions.httpsCallable(&quot;requestTurn&quot;).call(data) { (result, error) in
              print(&quot;Function returned&quot;)
              if let err = error {print(err)}
              if let res = result {print(res)}
              
          }
  </code></pre>
  <p>and the mail that was supposed to be sent is saved with no problem in the mail collection.
  <a href="https://i.stack.imgur.com/UiNXH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UiNXH.png" alt="firestore database" /></a></p>