问题
I'm using nodemailer to send emails, but my antivirus block the nodemailer. When I turn off the antivirus there is no problem sending emails.
Are there any possible way to send emails useing nodemailer without disabling antivirus?
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'username@gmail.com',
pass: 'password'
}
});
var mailOptions = {
from: 'username@gmail.com',
to: "to',
subject: 'subject',
html: '<div></div>'
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error)
} else {
console.log('Email sent: ' + info.response);
}
});
Error Message ->
{ Error: self signed certificate in certificate chain
at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:639:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38) code: 'ESOCKET',
command: 'CONN' }
回答1:
In your transporter
settings, try adding the following:
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'username@gmail.com',
pass: 'password'
},
// === add this === //
tls : { rejectUnauthorized: false }
});
You should now be able to send without disabling your antivirus.
来源:https://stackoverflow.com/questions/56033066/antivirus-is-blocking-nodemailer-error-self-signed-certificate-in-certificate