-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (37 loc) · 1.2 KB
/
Copy pathindex.js
File metadata and controls
45 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
exports.EmailSender = functions.https.onCall(async (data, context) => {
const email = data;
if (!email) {
return "Error: No email provided";
}
// Create transporter
const emailTransporter = nodemailer.createTransport({
service: 'gmail',
auth: { // replace with your credentials
user: '', // email
pass: '' // password
}
});
// Create email payload
const emailOptions = {
from: "FirebaseFlutterDemo Bot <firebaseflutterdemobot@gmail.com>",
to: email,
subject: "Hello from Firebase Cloud Functions!",
html: "<p>This email was sent through Firebase Cloud Functions.</p>"
}
// Send email
try {
await emailTransporter.sendMail(emailOptions, (err, info) => {
if (err) {
functions.logger.log("Error sending email: ", err);
return "Error";
}
})
} catch (err) {
functions.logger.log("Error sending email: ", err);
return "Error";
}
functions.logger.log("Sent an email to " + email);
return "Success!";
});