Примерно так, но надо проверять...
let express = require("express");
let app = express();
var nodemailer = require("nodemailer");
app.get('/', function (req, res) {
sendEmail('f@ya.ru', '1').then(() => {
console.log('sended')
res.send('sended')
}).catch((error) => {
console.log(error)
res.send('error')
// res.send(error.message)
})
// console.log(sendEmail('f@ya.ru', '1'));
});
function sendEmail(email, password) {
return new Promise((resolve, reject) => {
nodemailer.createTestAccount((err, account) => {
errortext = err;
let transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false,
auth: {
user: account.user,
pass: account.pass
}
});
let mailOptions = {
from: '"Heano" <games.1212@yandex.ru>',
to: email,
subject: 'Регистрация ✔',
text: 'Твой пароль: ' + password,
html: 'Твой пароль:<b> ' + password + '</b>'
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
reject(error)
// return false;
}
else {
resolve()
// return true;
}
});
});
})
}
let server = app.listen(2800, () => console.log("Работа пошла"));