使用 Firebase Cloud Functions 时 Nodemailer queryA EREFUSED localhost
Nodemailer queryA EREFUSED localhost when using Firebase Cloud Functions
只要在 Firebase 数据库中创建了新订单,我就会尝试向管理员帐户发送电子邮件。我为此使用了 Cloud Functions 和 Nodemailer,但出现以下错误:
Error: queryA EREFUSED localhost
at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19)
这是代码:
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: 'myemail@gmail.com',
pass: 'mypass'
}
});
exports.sendMail = functions.database.ref('/Order/{orderId}').onCreate((snapshot, context) =>{
const dest = 'destination@gmail.com';
const mailOptions = {
from: 'Risal Fajar <noreply@bukakata.com>',
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);
});
});
虽然输入了smtp.gmail.com[=13=,但不知道为什么报错localhost ]
编辑:我添加了 transport.verify(),这就是结果
{ Error: queryA EREFUSED localhost
at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19)
errno: 'EREFUSED',
code: 'EDNS',
syscall: 'queryA',
hostname: 'localhost',
command: 'CONN' }
已修复
我通过将传输器配置(更改服务名称)更改为:
来修复它
let transporter = nodemailer.createTransport({
service: 'gmail',
port: 465,
secure: true,
auth: {
user: 'myemail@gmail.com',
pass: 'mypass'
}
});
可以看到文档:https://nodemailer.com/usage/using-gmail/
gmail还有一个问题,关于这个问题,和我一样,
我得到这个错误:
Error: { Error: queryA EREFUSED smtp.163.com
at QueryReqWrap.onresolve [as oncomplete] (dns.js:199:19)
但是当我尝试在我的手机上使用 termux 运行 相同的代码时,它起作用了,也许免费的 smtp 服务太糟糕了。
只要在 Firebase 数据库中创建了新订单,我就会尝试向管理员帐户发送电子邮件。我为此使用了 Cloud Functions 和 Nodemailer,但出现以下错误:
Error: queryA EREFUSED localhost at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19)
这是代码:
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: 'myemail@gmail.com',
pass: 'mypass'
}
});
exports.sendMail = functions.database.ref('/Order/{orderId}').onCreate((snapshot, context) =>{
const dest = 'destination@gmail.com';
const mailOptions = {
from: 'Risal Fajar <noreply@bukakata.com>',
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);
});
});
虽然输入了smtp.gmail.com[=13=,但不知道为什么报错localhost ]
编辑:我添加了 transport.verify(),这就是结果
{ Error: queryA EREFUSED localhost at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19) errno: 'EREFUSED', code: 'EDNS', syscall: 'queryA', hostname: 'localhost', command: 'CONN' }
已修复
我通过将传输器配置(更改服务名称)更改为:
来修复它let transporter = nodemailer.createTransport({
service: 'gmail',
port: 465,
secure: true,
auth: {
user: 'myemail@gmail.com',
pass: 'mypass'
}
});
可以看到文档:https://nodemailer.com/usage/using-gmail/
gmail还有一个问题,关于这个问题,和我一样, 我得到这个错误:
Error: { Error: queryA EREFUSED smtp.163.com at QueryReqWrap.onresolve [as oncomplete] (dns.js:199:19)
但是当我尝试在我的手机上使用 termux 运行 相同的代码时,它起作用了,也许免费的 smtp 服务太糟糕了。