如果收件人电子邮件错误,则在Nodemailer中出错

问题描述 投票:0回答:1

我正在使用Nodemailer SMTP发送电子邮件

如果电子邮件帐户有效/存在,它可以正常工作,但是不存在输入电子邮件地址时出现500错误的错误。

我知道它没有发送,因为电子邮件不存在,但需要处理错误

我也尝试过tls: {rejectUnauthorized: false},,但遇到同样的问题

我使用自定义SMTP而不使用Gmail SMTP

我的代码如下:

let transporter = nodemailer.createTransport({
                host: 'smtp.myhost.de',
                port: 587,
                auth: {
                  user: 'CUSTOM_SMTP_EMAIL', // generated ethereal user
                  pass: 'CUSTOM_SMTP_PASS' // generated ethereal password
                },
                secure:false,
                requireTLS: false,
                tls: {rejectUnauthorized: false},
                debug:true
              });



let info = await transporter.sendMail({
                from: sails.config.custom.appName+ SENDER_EMAIL, // sender address
                to: inputs.email, // list of receivers
                subject: "My email subject ", // Subject line
                text: "Verify Email Address "+inputs.email, // plain text body
                html: html // html body
              },function(err) {
                console.log('email sent');

                if (err){
                    console.log( 'err->>>>>>>>>>>>>', err);
                    return exits.success('error');

                } else {
                   console.log('success');
                   return exits.success('success');
                }
              });

由于500错误,我无法返回return exits.success('error');

得到以下错误

err->>>>>>>>>>>>>>>

{ Error: Can't send mail - all recipients were rejected: 552 5.2.2 host gmail-smtp-in.l.google.com [2a00:1450:400c:c09::1a] said: The email account that you tried to reach is over quota. Please direct the recipient to https://support.google.com/mail/?p=OverQuotaPerm q13si8918761wrn.204 - gsmtp (H-QUOTA)
    at SMTPConnection._formatError (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
    at SMTPConnection._actionRCPT (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:1613:28)
    at SMTPConnection._responseActions.push.str (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:1566:30)
    at SMTPConnection._processResponse (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
    at SMTPConnection._onData (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
    at TLSSocket.SMTPConnection._onSocketData.chunk (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at TLSSocket.Readable.push (_stream_readable.js:208:10)
    at TLSWrap.onread (net.js:607:20)
  code: 'EENVELOPE',
  response: '552 5.2.2 host gmail-smtp-in.l.google.com [2a00:1450:400c:c09::1a] said: The email account that you tried to reach is over quota. Please direct the recipient to https://support.google.com/mail/?p=OverQuotaPerm q13si8918761wrn.204 - gsmtp (H-QUOTA)',
  responseCode: 552,
  command: 'RCPT TO',
  rejected: [ '[email protected]' ],
  rejectedErrors:
   [ { Error: Recipient command failed: 552 5.2.2 host gmail-smtp-in.l.google.com [2a00:1450:400c:c09::1a] said: The email account that you tried to reach is over quota. Please direct the recipient to https://support.google.com/mail/?p=OverQuotaPerm q13si8918761wrn.204 - gsmtp (H-QUOTA)
    at SMTPConnection._formatError (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
    at SMTPConnection._actionRCPT (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:1599:24)
    at SMTPConnection._responseActions.push.str (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:1566:30)
    at SMTPConnection._processResponse (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
    at SMTPConnection._onData (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
    at TLSSocket.SMTPConnection._onSocketData.chunk (/var/www/html/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at TLSSocket.Readable.push (_stream_readable.js:208:10)
    at TLSWrap.onread (net.js:607:20)
       code: 'EENVELOPE',
       response: '552 5.2.2 host gmail-smtp-in.l.google.com [2a00:1450:400c:c09::1a] said: The email account that you tried to reach is over quota. Please direct the recipient to https://support.google.com/mail/?p=OverQuotaPerm q13si8918761wrn.204 - gsmtp (H-QUOTA)',
       responseCode: 552,
       command: 'RCPT TO',
       recipient: '[email protected]' } ] }
javascript node.js sails.js nodes nodemailer
1个回答
1
投票

如果没有将回调作为第二个参数传递给sendMail,它将返回一个可以等待的承诺:

let info = await transporter.sendMail({
    from: sails.config.custom.appName+ SENDER_EMAIL, // sender address
    to: inputs.email, // list of receivers
    subject: "My email subject ", // Subject line
    text: "Verify Email Address "+inputs.email, // plain text body
    html: html // html body
}).then(() => {
    console.log('success');
    return exits.success('success');
}).catch((err) => {
    console.log( 'err->>>>>>>>>>>>>', err);
    return exits.success('error');
});

console.log(info);
© www.soinside.com 2019 - 2024. All rights reserved.