tidy email settings

This commit is contained in:
Dobromir Popov
2024-04-19 17:01:51 +03:00
parent 91adc27d29
commit 4cf62b2fbd
5 changed files with 48 additions and 99 deletions

View File

@ -13,75 +13,30 @@ const Handlebars = require('handlebars');
const { Shift, Publisher, PrismaClient } = require("@prisma/client");
const { env } = require("../../next.config");
const SMTPTransport = require("nodemailer/lib/smtp-transport");
// const TOKEN = process.env.TOKEN || "a7d7147a530235029d74a4c2f228e6ad";
// const SENDER_EMAIL = "sofia@mwitnessing.com";
// const sender = { name: "Специално Свидетелстване София", email: SENDER_EMAIL };
// const client = new MailtrapClient({ token: TOKEN });
let mailtrapTestClient = null;
// const mailtrapTestClient = new MailtrapClient({
// username: '8ec69527ff2104',//not working now
// password: 'c7bc05f171c96c'
// });
//MAILTRAP
var transporterMT = nodemailer.createTransport({
host: process.env.MAILTRAP_HOST || "sandbox.smtp.mailtrap.io",
port: 2525,
auth: {
user: process.env.MAILTRAP_USER,
pass: process.env.MAILTRAP_PASS
}
});
//PROD GMAIL
// const oauth2Client = new OAuth2(
// process.env.CLIENT_ID,
// process.env.CLIENT_SECRET,
// "https://developers.google.com/oauthplayground"
// );
// var transporterGmail = nodemailer.createTransport({
// service: "gmail",
// auth: {
// type: "OAuth2",
// user: process.env.GMAIL_USER,
// clientId: process.env.CLIENT_ID,
// clientSecret: process.env.CLIENT_SECRET,
// refreshToken: process.env.REFRESH_TOKEN,
// accessToken: process.env.ACCESS_TOKEN
// }
// });
//--------------
var transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_GMAIL_USERNAME,
pass: process.env.EMAIL_GMAIL_APP_PASS
}
});
//PROD MAILERSEND
// var transporter = nodemailer.createTransport({
// host: process.env.MAILERSEND_SERVER,
// port: process.env.MAILERSEND_PORT,
// auth: {
// user: process.env.MAILERSEND_USER,
// pass: process.env.MAILERSEND_PASS
// }
// });
var transporterBulk = nodemailer.createTransport({
host: "bulk.smtp.mailtrap.io",
port: 587,
auth: {
user: "api",
pass: "1cfe82e747b8dc3390ed08bb16e0f48d"
}
});
var transporter;
if (process.env.EMAIL_SERVICE.toLowerCase() === "mailtrap") {
transporter = nodemailer.createTransport({
host: process.env.MAILTRAP_HOST || "sandbox.smtp.mailtrap.io",
port: process.env.MAILTRAP_PORT || 2525,
auth: {
user: process.env.MAILTRAP_USER,
pass: process.env.MAILTRAP_PASS
}
});
}
if (process.env.EMAIL_SERVICE.toLowerCase() === "gmail") {
transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_GMAIL_USERNAME,
pass: process.env.EMAIL_GMAIL_APP_PASS
}
});
}
// ------------------ Email sending ------------------
@ -137,22 +92,11 @@ exports.SendEmail = async function (to, subject, text, html, attachments = []) {
attachments
};
if (mailtrapTestClient !== null) {
// Assuming mailtrapTestClient is correctly set up to send emails
await mailtrapTestClient
.send(message)
.then(console.log)
.catch(console.error);
} else {
let result = await transporter
.sendMail(message)
.then(console.log)
.catch(console.error);
return result;
}
let result = await transporter
.sendMail(message)
.then(console.log)
.catch(console.error);
return result;
};
exports.SendEmailHandlebars = async function (to, templateName, model, attachments = []) {