Files
classroomio/apps/backend/src/utils/email.js
T

40 lines
971 B
JavaScript
Raw Normal View History

2024-08-10 09:58:33 +01:00
const { SendMailClient } = require('zeptomail');
const nodemailer = require('nodemailer');
2024-09-18 04:26:24 +01:00
const { ZOHO_TOKEN, SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD } = process.env;
2024-08-10 09:58:33 +01:00
const zohoClient = new SendMailClient({ url: 'api.zeptomail.eu/', token: ZOHO_TOKEN });
2024-09-18 04:26:24 +01:00
const nodemailerTransporter = async () => {
if (!SMTP_HOST || !SMTP_PORT || !SMTP_USER || !SMTP_PASSWORD) {
2024-08-10 09:58:33 +01:00
console.error('SMTP configuration missing');
return null;
}
2024-09-28 20:54:36 +01:00
console.log({
SMTP_HOST,
SMTP_PORT,
SMTP_USER,
SMTP_PASSWORD
});
2024-08-10 09:58:33 +01:00
try {
const transporter = nodemailer.createTransport({
host: SMTP_HOST,
port: parseInt(SMTP_PORT || '465', 10),
secure: true,
auth: {
2024-09-18 04:26:24 +01:00
user: SMTP_USER,
pass: SMTP_PASSWORD
2024-08-10 09:58:33 +01:00
}
});
await transporter.verify();
return transporter;
} catch (error) {
console.error('Transporter error:', error);
return null;
}
};
module.exports = { nodemailerTransporter, zohoClient };