title: How to send email in Firebase for free?
body: <p>I'm aware that Firebase doesn't allow you to send emails using 3rd party email services. So the only way is to send through Gmail.</p>
  
  <p>So I searched the internet for ways, so here's a snippet that works and allows me to send email without cost.</p>
  
  <pre><code>export const shareSpeechWithEmail = functions.firestore
    .document("/sharedSpeeches/{userId}")
    .onCreate(async (snapshot, context) =&gt; {
      // const userId = context.params.userId;
      // const data = snapshot.data();
      const mailTransport = nodemailer.createTransport(
        `smtps://${process.env.USER_EMAIL}:${process.env.USER_PASSWORD}@smtp.gmail.com`
      );
  
  
      const mailOptions = {
        to: "test@gmail.com",
        subject: `Message test`,
        html: `&lt;p&gt;&lt;b&gt;test&lt;/b&gt;&lt;/p&gt;`
      };
      try {
        return mailTransport.sendMail(mailOptions);
      } catch (err) {
        console.log(err);
        return Promise.reject(err);
      }
    });
  
  </code></pre>
  
  <p>I want to create a template, so I used this package called <code>email-templates</code> for nodemailer.
  But the function doesn't get executed in Firebase Console and it doesn't show an error and shows a warning related to "billing".</p>
  
  <pre><code>export const shareSpeechWithEmail = functions.firestore
    .document("/sharedSpeeches/{userId}")
    .onCreate(async (snapshot, context) =&gt; {
  
      const email = new Email({
        send: true,
        preview: false,
        views: {
          root: path.resolve(__dirname, "../../src/emails")
          // root: path.resolve(__dirname, "emails")
        },
        message: {
          // from: "&lt;noreply@domain.com&gt;"
          from: process.env.USER_EMAIL
        },
        transport: {
          secure: false,
          host: "smtp.gmail.com",
          port: 465,
          auth: {
            user: process.env.USER_EMAIL,
            pass: process.env.USER_PASSWORD
          }
        }
      });
  
      try {
        return email.send({
          template: "sharedSpeech",
          message: {
            to: "test@gmail.com",
            subject: "message test"
          },
          locals: {
            toUser: "testuser1",
            fromUser: "testuser2",
            title: "Speech 1",
            body: "&lt;p&gt;test using email &lt;b&gt;templates&lt;/b&gt;&lt;/p&gt;"
          }
        });
      } catch (err) {
        console.log(err);
        return Promise.reject(err);
      }
    });
  </code></pre>