如何使用 nodemailer 从公司域 Outlook 帐户发送邮件?

时间:2021-02-16 11:58:15

标签: node.js outlook nodemailer

我正在尝试使用 outlooknodemailer 帐户发送电子邮件。我无法使用此 outlookuserid 登录 password。但是我可以在这个主机上登录:mail.ownDomain

这是我目前所做的:

var mailConf = {
    host: "smtp.office365.com", 
    secureConnection: false, 
    port: 587,
    tls: {
        ciphers: 'SSLv3'
    },
    auth: {
        user: 'userID',
        pass: 'password'
    }
};

var transporter = nodemailer.createTransport(config.mailConf);

transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
        console.log(error);
    } else {
        console.log('Email sent: ' + info.response);
    }
});

并得到这个错误:

{ 
    Error: Invalid login: 535 5.7.3 Authentication unsuccessful [SG2PR06CA0241.apcprd06.prod.outlook.com]
        at SMTPConnection._formatError (H:\vsOnline\EzAssist\web\node_modules\nodemailer\lib\smtp-connection\index.js:605:19)
        at SMTPConnection._actionAUTHComplete (H:\vsOnline\EzAssist\web\node_modules\nodemailer\lib\smtp-connection\index.js:1340:34)
        at SMTPConnection._responseActions.push.str (H:\vsOnline\EzAssist\web\node_modules\nodemailer\lib\smtp-connection\index.js:1298:18)
        at SMTPConnection._processResponse (H:\vsOnline\EzAssist\web\node_modules\nodemailer\lib\smtp-connection\index.js:764:20)
        at SMTPConnection._onData (H:\vsOnline\EzAssist\web\node_modules\nodemailer\lib\smtp-connection\index.js:570:14)
        at TLSSocket._socket.on.chunk (H:\vsOnline\EzAssist\web\node_modules\nodemailer\lib\smtp-connection\index.js:710:55)
        at TLSSocket.emit (events.js:198:13)
        at addChunk (_stream_readable.js:288:12)
        at readableAddChunk (_stream_readable.js:269:11)
        at TLSSocket.Readable.push (_stream_readable.js:224:10)
    code: 'EAUTH',
    response:
    '535 5.7.3 Authentication unsuccessful [SG2PR06CA0241.apcprd06.prod.outlook.com]',
    responseCode: 535,
    command: 'AUTH LOGIN' 
 }

然后我尝试将 host 更改为 mail.ownDomain 但得到这个错误:

{ 
  Error: getaddrinfo ENOTFOUND smtp.mail.ownDomain smtp.mail.ownDomain:587
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
  errno: 'ENOTFOUND',
  code: 'ECONNECTION',
  syscall: 'getaddrinfo',
  hostname: 'smtp.mail.ownDomain',
  host: 'smtp.mail.ownDomain',
  port: 587,
  command: 'CONN' 
}

0 个答案:

没有答案
相关问题