I was working with a client who had a frontend app that needed to send/receive emails. The client didn't have a backend server and didn't want to have one, but had a SMTP server included in his server provider so I got a good opportunity to try cloud functions ( which are free in firebase )
I personally think is always better to have a robuts backend server but in this case the client didn't want to have one....
Will go thru the code but main idea is that I can hide the nodemailer configs and secerts and in frontend I will have a box to fill text in and a "Send" button, which call the Cloud funtion, construct an email, and send the email with the question from the user to my client,
IMPORTANT: configure correctly your functions panel to allow only your domain to call the function.
Let's start
first of all spin up a project following this Firebase Docs
in the index.js import the required libraries and initialize the firebase app
I'm using nodemailer to send emails, so I'm gonna need the email user and password, which can be hardcoded but lets keep it clean and import from enviroment variables, in this case I'm using 2 email accounts, the no-reply one, that will send things, and 2nd one that will receive the emails.