首页 > 解决方案 > 在不使用 gmail smtp 的情况下发送电子邮件 nodemailer

问题描述

我有一封使用bell.net电子邮件地址的企业电子邮件,在他们的网站上,它说 use smtphm.sympatico.ca,作为 smtp 主机名,以及port 25 / 587......我的 nodemailer 代码设置如下:

 app.post('/sendBatchEmail', (req, res) => {
    var emails = [];
    var emailSubject = req.body.emailSubject;
    var emailMessage = req.body.emailMessage;

    //perform db2 send
    var sendEmail = "select * from testEmails"
    ibmdb.open(ibmdbconnMaster, function (err, conn) {
      if (err) return console.log(err);
      conn.query(sendEmail, function (err, rows) {
        if (err) {
          console.log(err);
        }
        for (var i = 0; i < rows.length; i++) {
          emails.push(rows[i].EMAIL)
        }
       
        //send email
        async function main() {
          
          let transporter = nodemailer.createTransport({
            host: "smtphm.sympatico.ca",
            port: 25,
            secure: false, // true for 465, false for other ports
            auth: {
              user: "xxx@bell.net",
              pass: "xxx",
            },
          });
      
          // send mail with defined transport object
          let sendBatch = await transporter.sendMail({
            from: "my1email@bell.net", // sender address
            to: "myemail@gmail.com",
            bcc: emails, // list of receivers
            subject: emailSubject, // Subject line
            text: emailMessage, // plain text body
          });
          
      
          console.log("Message sent: %s", sendBatch.messageId);
          // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
      
          // Preview only available when sending through an Ethereal account
          // console.log("Preview URL: %s", sendBatch.getTestMessageUrl);
          // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
        }
      
        main().catch(console.error);
        res.redirect("/");

        conn.close(function () {
          console.log("closed the function app.get(/sendEmailBatch)");
        });
      });
    });

  })

但是,这不起作用并给了我这个错误:

    Error: Invalid login: 535 Authentication failed
    at SMTPConnection._formatError (/Users/ga/Desktop/PSL/mbs/node_modules/nodemailer/lib/smtp-connection/index.js:774:19)
    at SMTPConnection._actionAUTHComplete (/Users/ga/Desktop/PSL/mbs/node_modules/nodemailer/lib/smtp-connection/index.js:1513:34)
    at SMTPConnection.<anonymous> (/Users/ga/Desktop/PSL/mbs/node_modules/nodemailer/lib/smtp-connection/index.js:540:26)
    at SMTPConnection._processResponse (/Users/ga/Desktop/PSL/mmbs/node_modules/nodemailer/lib/smtp-connection/index.js:932:20)
    at SMTPConnection._onData (/Users/ga/Desktop/PSL/mbs/node_modules/nodemailer/lib/smtp-connection/index.js:739:14)
    at TLSSocket.SMTPConnection._onSocketData (/Users/ga/Desktop/PSL/mbs/node_modules/nodemailer/lib/smtp-connection/index.js:189:44)
    at TLSSocket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at TLSSocket.Readable.push (internal/streams/readable.js:223:10) {
  code: 'EAUTH',
  response: '535 Authentication failed',
  responseCode: 535,
  command: 'AUTH PLAIN'
}

但是当我将其改回gmail时可以使用...有什么想法吗?

标签: javascriptsqlnode.jsnodemailer

解决方案


推荐阅读