如何使用SMTP使用nodemailer发送邮件

时间:2019-03-27 14:01:13

标签: node.js nodemailer email-templates

我正在尝试使用smtp作为服务器/主机,并在节点侧使用nodemailer来以我的代码发送电子邮件。但是在我所有凭据都还可以的情况下,它给了我未经授权的错误。

smtp作为服务器/主机,在节点侧具有nodemailer。

 var transporter = nodemailer.createTransport( {
                host: "smtp.wgs.wuerth.com",
                port: 25,
                secure: false,
                auth: {
                    user: '*********',
                    pass: '*********',
                },
                tls: {
                    // do not fail on invalid certs
                    rejectUnauthorized: false,
                }
            } );

  transporter.verify( function ( error, success ) {
    if ( error ) {
      console.log('====>'+ error );
    } else {
      console.log( "Server is ready to take our messages" );
    }
  } );
        const email = new Email( {
            message: {
                from: 'aayushi.kumar@wurth-it.in'
            },

            transport: transporter,
            send: true,
        } );

        email.send( {
            message: {
                to: user.email,
                subject: 'forgot password',
            },

            template: templateDir,
            locals: {
                first_name: user.first_name + ' ' + user.last_name,
                password: password
            },
        } )
            .then( console.log )
            .catch( console.error );

我希望发送邮件

但是我得到

Error: Invalid login: 535 5.7.3 Authentication unsuccessful
at SMTPConnection._formatError (D:\Projects\Click-2-Order_Mysql\Node\node_modules\nodemailer\lib\smtp-connection\index.js:605:19)
at SMTPConnection._actionAUTHComplete (D:\Projects\Click-2-Order_Mysql\Node\node_modules\nodemailer\lib\smtp-connection\index.js:1340:34)
at SMTPConnection._responseActions.push.str (D:\Projects\Click-2-Order_Mysql\Node\node_modules\nodemailer\lib\smtp-connection\index.js:1298:18)
at SMTPConnection._processResponse (D:\Projects\Click-2-Order_Mysql\Node\node_modules\nodemailer\lib\smtp-connection\index.js:764:20)
at SMTPConnection._onData (D:\Projects\Click-2-Order_Mysql\Node\node_modules\nodemailer\lib\smtp-connection\index.js:570:14)
at TLSSocket._socket.on.chunk (D:\Projects\Click-2-Order_Mysql\Node\node_modules\nodemailer\lib\smtp-connection\index.js:710:55)
at TLSSocket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at TLSSocket.Readable.push (_stream_readable.js:219:10)
at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
 code: 'EAUTH',
  response: '535 5.7.3 Authentication unsuccessful',
  responseCode: 535,
  command: 'AUTH LOGIN' }

0 个答案:

没有答案