问题
I'm building a web app with firebase and cloud functions. I have a cloud function that creates a verification code every time an new user wants to subscribe and I need to send via email this verification code. I'm trying to use nodemailer with AWS Simple Email Sender. I have my SMTP credentials for AWS SES and this code works perfectly on my localhost but when I deploy this cloud function to firebase I doesnt work and I get this error.
{ Error: queryA EREFUSED email-smtp.us-east-1.amazonaws.com
at QueryReqWrap.onresolve [as oncomplete] (dns.js:213:19)
errno: 'EREFUSED',
code: 'EDNS',
syscall: 'queryA',
hostname: 'email-smtp.us-east-1.amazonaws.com',
command: 'CONN' }
I'm using node mailer example.
const nodemailer = require('nodemailer');
async function main() {
let transporter = nodemailer.createTransport({
host: 'email-smtp.us-east-1.amazonaws.com',
port: 465,
secure: true,
auth: {
user: 'thisisfake@fake.com',
pass: 'thisisfake'
}
});
let info = await transporter.sendMail({
from: '"Fred Foo 👻" <foo@example.com>',
to: 'bar@example.com, baz@example.com',
subject: 'Hello ✔', // Subject line
text: 'Hello world?', // plain text body
html: '<b>Hello world?</b>' // html body
});
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
}
main().catch(console.error);
回答1:
My assumption is that you use the free ("spark") tier of Cloud Functions for Firebase. These kind of functions does not allow network connections outside of Google. In order to solve your issue you would need to use theBlaze plan where the connections are allowed and where you "pay as you go". Even with the Blaze plan you have the free usage of the spark plan included which allow a reasonable level of development and usage without any charges.
来源:https://stackoverflow.com/questions/57729409/nodemailer-and-aws-ses-erefused-error-when-using-cloud-functions