Skip to content

Instantly share code, notes, and snippets.

@rizqyhi
Created Apr 14, 2017
Embed
What would you like to do?
Belajar Firebase Functions: Kirim Email dari Contact Form
var functions = require('firebase-functions');
var nodemailer = require('nodemailer');
// Setting email dan password pengirim
const gmailEmail = 'email.kamu@gmail.com';
const gmailPass = 'password.email.kamu';
const mailer = nodemailer.createTransport({
service: 'Gmail',
auth: {user: gmailEmail, pass: gmailPass}
});
// Mendefinisikan fungsi dengan HTTP trigger
exports.sendEmail = functions.https.onRequest(function (req, res) {
var text = [
'Pengirim: '+req.body.email,
'Subjek: '+req.body.subject,
'Pesan: '+req.body.message
];
var message = {
from: req.body.email,
to: gmailEmail,
replyTo: req.body.email,
subject: 'Pesan baru dari contact form: '+req.body.subject,
text: text.join("\n")
}
return mailer.sendMail(message).then(function () {
res.send('Email terkirim!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment