mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
* change name of auth.service to AuthService * Add emailEnabled to config api * Setup email * update nodemailer version * add translations * update .env.example * clean up console.log's) * refactor RequestPasswordReset component * chore: rebuild package-lock.json --------- Co-authored-by: Daniel Avila <messagedaniel@protonmail.com>
43 lines
1 KiB
JavaScript
43 lines
1 KiB
JavaScript
const nodemailer = require('nodemailer');
|
|
const handlebars = require('handlebars');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const sendEmail = async (email, subject, payload, template) => {
|
|
try {
|
|
const transporter = nodemailer.createTransport({
|
|
service: process.env.EMAIL_SERVICE,
|
|
auth: {
|
|
user: process.env.EMAIL_USERNAME,
|
|
pass: process.env.EMAIL_PASSWORD,
|
|
},
|
|
});
|
|
|
|
const source = fs.readFileSync(path.join(__dirname, 'emails', template), 'utf8');
|
|
const compiledTemplate = handlebars.compile(source);
|
|
const options = () => {
|
|
return {
|
|
from: process.env.EMAIL_FROM,
|
|
to: email,
|
|
subject: subject,
|
|
html: compiledTemplate(payload),
|
|
};
|
|
};
|
|
|
|
// Send email
|
|
transporter.sendMail(options(), (error, info) => {
|
|
if (error) {
|
|
console.log(error);
|
|
return error;
|
|
} else {
|
|
console.log(info);
|
|
return info;
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.log(error);
|
|
return error;
|
|
}
|
|
};
|
|
|
|
module.exports = sendEmail;
|