Nodemailer - MS Exchange 服务器 - 无法验证第一个证书时出错
Nodemailer - MS Exchaneg server - Error unable to verify the first certificate
我正在尝试使用办公室外的 MS Exchange 邮件服务器从 NodeJS 发送电子邮件。使用以下代码。并得到错误
我们的管理员说不需要证书。
错误:-
$ node test2.js
Error : { Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1048:34)
at TLSSocket.emit (events.js:182:13)
at TLSSocket._finishInit (_tls_wrap.js:628:8) code: 'ESOCKET', command: 'CONN' }
NodeJS代码:-
"use strict";
const nodemailer = require("nodemailer");
async function main() {
try {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'host',
port: 25,
secure : false, // true for 465, false for other ports
auth: {
user: 'user',
pass: 'password'
}
});
// setup email data
let mailOptions = {
from: 'me@email.com',
to: 'me@email.com',
subject: 'Hey you, awesome!',
html: '<b>This is bold text</b>',
text: 'This is text version!'
};
// send mail with defined transport object
let info = await transporter.sendMail(mailOptions)
console.log("Message sent: %s", JSON.stringify(info));
} catch (error) {
console.log('Error : ', error);
}
}
main(); // For testing
下面的代码更改解决了这个问题。将此添加到 createTransport()
tls: {rejectUnauthorized: false}
代码:-
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'host',
port: 25,
secure : false, // true for 465, false for other ports
auth: {
user: 'user',
pass: 'password'
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
},
});
我正在尝试使用办公室外的 MS Exchange 邮件服务器从 NodeJS 发送电子邮件。使用以下代码。并得到错误
我们的管理员说不需要证书。
错误:-
$ node test2.js
Error : { Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1048:34)
at TLSSocket.emit (events.js:182:13)
at TLSSocket._finishInit (_tls_wrap.js:628:8) code: 'ESOCKET', command: 'CONN' }
NodeJS代码:-
"use strict";
const nodemailer = require("nodemailer");
async function main() {
try {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'host',
port: 25,
secure : false, // true for 465, false for other ports
auth: {
user: 'user',
pass: 'password'
}
});
// setup email data
let mailOptions = {
from: 'me@email.com',
to: 'me@email.com',
subject: 'Hey you, awesome!',
html: '<b>This is bold text</b>',
text: 'This is text version!'
};
// send mail with defined transport object
let info = await transporter.sendMail(mailOptions)
console.log("Message sent: %s", JSON.stringify(info));
} catch (error) {
console.log('Error : ', error);
}
}
main(); // For testing
下面的代码更改解决了这个问题。将此添加到 createTransport()
tls: {rejectUnauthorized: false}
代码:-
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'host',
port: 25,
secure : false, // true for 465, false for other ports
auth: {
user: 'user',
pass: 'password'
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
},
});