Nodemailer and AWS SES EREFUSED error when using cloud functions

不打扰是莪最后的温柔 提交于 2020-04-30 19:28:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!