hi, i got error when try to send email using SMTP
root@sg01:/home/node# node stats.js
SMTP Configured
Sending Mail
Error occurred
self signed certificate
this my test script
var mailer = require('nodemailer');
var transporter = mailer.createTransport({
host: '128.199.226.xxx',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'xxx'
}
});
console.log('SMTP Configured');
// Message object
var message = {
// sender info
from: 'KabarGames <[email protected]>',
// Comma separated list of recipients
to: "tes" <[email protected]>',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
// plaintext body
text: 'Hello to myself!',
// HTML body
html: '<p><b>Hello</b> to myself <img src="cid:[email protected]"/></p>' +
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:[email protected]"/></p>',
// Apple Watch specific HTML body
watchHtml: '<b>Hello</b> to myself',
};
console.log('Sending Mail');
transporter.sendMail(message, function(error, info) {
if (error) {
console.log('Error occurred');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
console.log('Server responded with "%s"', info.response);
});
Try adding this:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
It tells Node to accept self signed certificates.
You can use this as well:
nodemailer.createTransport({
host:'...',
...,
tls:{
rejectUnauthorized: false
}
});
Deleted my comment cause i figured that out. Thanks for the quick response tho! I think the docs could use a bit of improvement, which I'll continue to do as I puzzle out how to make email work for me.
Most helpful comment
You can use this as well: