I'm trying to send email to admin account whenever there's a new Order created in Firebase Database. I'm using Cloud Functions and Nodemailer for this, but I got below error:
Error: queryA EREFUSED localhost at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19)
And this is the code:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
admin.initializeApp();
/**
* Here we're using Gmail to send
*/
let transporter = nodemailer.createTransport({
service: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'mypass'
}
});
exports.sendMail = functions.database.ref('/Order/{orderId}').onCreate((snapshot, context) =>{
const dest = '[email protected]';
const mailOptions = {
from: 'Risal Fajar <[email protected]>',
to: dest,
subject: 'I\'M A PICKLE!!!',
html: `<p style="font-size: 16px;">Pickle Riiiiiiiiiiiiiiiick!!</p>
<br />
<img src="https://images.prod.meredith.com/product/fc8754735c8a9b4aebb786278e7265a5/1538025388228/l/rick-and-morty-pickle-rick-sticker" />
`
};
// returning result
return transporter.sendMail(mailOptions).then(() => {
console.log('Mail sent to ', dest);
});
});
I don't know why the error showed localhost even though I've entered smtp.gmail.com
EDIT: I've added transport.verify() and this is the result
{ Error: queryA EREFUSED localhost at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19) errno: 'EREFUSED', code: 'EDNS', syscall: 'queryA', hostname: 'localhost', command: 'CONN' }