Sending email from contact form using firebase functions and possibly nodemailer

The technologies that I use

  • Angular 4
  • Firebase
  • firebase hosting
  • firebase functions
  • firebase realtime database
  • firebase storage

I am hosting my site on firebase hosting and I have a contact form like the picture, I want to send an email to the website admin every time the user submits this form, how can I send emails with firebase and Nodemailer How is this possible, I'm new to firebase functions and I'm not sure how to do this.

Can I require nodemailer inside index.js in the features folder or is this wrong?

I have a contact form like this picture

enter image description here

+3


source to share


1 answer


It is always helpful to ask when you are unsure how to do it. Here I will try to give you some simple steps on how to achieve this.

First of all, make sure you initialize Firebase functions inside your project. If you don't know how to do it, just google, on their corporate site they have amazing explanations on every topic.

With this done, configure one Firebase function using an HTTP trigger. Make sure inside the Firebase functions folder in your project you run npm install nodemailer@2.4.1 --save

. This is a defining moment when you actually install version 2.4.1, as all of them subsequently crash when trying to deploy this feature. (I still don't understand why)

EDIT:

I just found out what is the reason for Firebase functions to crash with newer version of Nodemailer. This was the Node version I was running. After updating my Node, everything was fine. The issue is also mentioned here: Link to official GitHub page

So, it's still up to you which version you prefer, just make sure that if you are using the latest version of Nodemailer, it also requires a newer Node.;)



After that open your Firebase function code, go to Nodemailer official site, see how one post is composed and sent. There's an awesome example in there that actually basically copies into your code, with some additional configurations (username and password).

Make sure from your external Angular app you are making a POST request with data from whatever fields you have in the form. You should also make sure that when your Firebase function receives a request, it sets up an email, sends it, and finally responds with the appropriate status code and message.

Everything I have written may sound a little complicated, I have no idea about your ICT competency, but make sure you read it carefully, Google that you do not understand, and if you still cannot find the answers, make sure what is what you answer here so that I or other people can help you.

I will also provide a link that you can use to guide yourself during this process.

Click here to see an example from Google themselves

Wish you luck.

+3


source







All Articles