Domain support

This commit is contained in:
salvacybersec
2025-11-10 20:01:41 +03:00
parent dea1b874b5
commit f86cda2978
24 changed files with 3703 additions and 34 deletions

View File

@@ -45,14 +45,19 @@ class MailService {
}
}
async sendMail(to, subject, htmlBody) {
async sendMail(to, subject, htmlBody, fromName = null) {
try {
if (!this.transporter) {
await this.initializeTransporter();
}
// Use custom from_name if provided, otherwise use default
const from = fromName
? `${fromName} <${this.fromAddress.match(/<(.+)>/)?.[1] || this.fromAddress}>`
: this.fromAddress;
const mailOptions = {
from: this.fromAddress,
from,
to,
subject,
html: htmlBody,

View File

@@ -5,7 +5,7 @@ const logger = require('../config/logger');
class TokenService {
async createToken(data) {
const { company_id, target_email, employee_name, template_type } = data;
const { company_id, target_email, employee_name, template_type, from_name } = data;
// Generate unique token
let token = generateTrackingToken();
@@ -45,6 +45,7 @@ class TokenService {
target_email,
employee_name,
template_type,
from_name: from_name || null,
mail_subject: template.subject_template.replace('{{company_name}}', company.name),
});
@@ -78,8 +79,13 @@ class TokenService {
throw new Error('Mail template not found');
}
// Get base URL from settings or env
const { Settings } = require('../models');
const baseUrlSetting = await Settings.findOne({ where: { key: 'base_url' } });
const baseUrl = baseUrlSetting?.value || process.env.BASE_URL || 'http://localhost:3000';
// Prepare template data
const trackingUrl = `${process.env.BASE_URL}/t/${token.token}`;
const trackingUrl = `${baseUrl}/t/${token.token}`;
const currentDate = new Date().toLocaleDateString('tr-TR', {
year: 'numeric',
month: 'long',
@@ -99,8 +105,8 @@ class TokenService {
const htmlBody = mailService.renderTemplate(template.body_html, templateData);
const subject = mailService.renderTemplate(template.subject_template, templateData);
// Send mail
await mailService.sendMail(token.target_email, subject, htmlBody);
// Send mail with custom from_name if provided
await mailService.sendMail(token.target_email, subject, htmlBody, token.from_name);
// Update token
await token.update({