I am currently utilizing Angular 4, Firebase Database, and Cloud Functions. I have a query: How can I trigger a Firebase Function upon clicking a button in my component?
Here's the scenario I'm aiming for: Triggering the sending of a test email using emailjs when a button is clicked.
Below is a snippet of my code:
functions/src/index.ts
import * as functions from 'firebase-functions';
const emailjs = require("emailjs/email");
export const sendMail = functions.https.onRequest((request, response) => {
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.your-email.com",
ssl: true
});
// sending the message and receiving callback with error details or message sent details
server.send({
text: "i hope this works",
from: "you <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c6c0d6c1ddd2ded6f3cadcc6c19ed6ded2dadf9dd0dcde">[email protected]</a>>",
to: "someone <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afdcc0c2cac0c1caefd6c0dadd82cac2cec6c381ccc0c2">[email protected]</a>>, another <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e1808f8e95898493a1988e9493cc848c80888dcf828e8c">[email protected]</a>>",
cc: "else <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c09001f092c1503191e4109010d0500420f0301">[email protected]</a>>",
subject: "testing emailjs"
}, function(err, message) { console.log(err || message); });
})
My component
sendTestEmail() {
// Within this function, I aim to call the "sendMail" function from Firebase to initiate the email sending process.
}
Now it comes down to this question: How do I properly invoke a Firebase Function from within my component?