0

I've a NestJS application deployed to Firebase wired up with Firebase functions. I've an API which accepts a form data from a different Firebase Angular frontend project (I prefer the BE and FE projects to be separated).

I'd like to send that contact form data through my NestJS backend due to validation purposes via email to the Firebase admin email address (my Google account email) with all the form data, after the validation is succeeded.

So it's basiacally a contact form, by the user, to the admin. I've digged through the documentation and I've found solutions only for the other direction, so the app sends email to the users after something triggers this function (with Nodemailer, and with a 3rd party SMTP mail service).

Is there a solution to send the contact form data to my Gmail (associated with the Firebase account too) in the desired way? Do I really need to use Nodemailer and a 3rd party service to send an email to myself with the data from the contact form?

The process flow should be the following:

  1. Users fills out the contact form
  2. After FE validation the data is sent to the NestJS API
  3. After BE validation the data is sent to my Gmail email address

Thanks for the suggestions in advance!

elyndel

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
ergondar
  • 33
  • 6

1 Answers1

0

Using Nodemailer would be the easiest option to send an email. You can use the same recipient email as the sender so you don't need any other mail service like SendGrid. Just specify the same email in both from and to:

const mailOptions = {
  from: "user@gmail.com",
  to: "user@gmail.com",
  subject: "New registration",
  text: "<Details>",
};

transporter.sendMail(mailOptions, function (error, info) {
  if (error) {
    console.log(error);
  } else {
    console.log("Email sent: " + info.response);
  }
});
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • But I still need an SMTP host for Nodemailer transporter. My question is whether I can do this functionality purely with Firebase or not. I don't really want to have an exetrnal dependency if that is possible. – ergondar Jan 29 '23 at 11:51
  • @elyndel you don't need your own SMTP server if you are using GMail to send the mail as in my code. You can follow [this answer](https://stackoverflow.com/a/45479968/13130697) for Nodemailer and Gmail related setup. – Dharmaraj Jan 29 '23 at 12:17