This commit is contained in:
2025-05-21 00:12:49 +00:00
parent 5c85188183
commit b1890f59ee
27 changed files with 2096 additions and 705 deletions

View File

@ -2,7 +2,7 @@ import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import { Email } from '../core/classes.email.js';
import { EmailSignJob } from './classes.emailsignjob.js';
import type { MtaService } from './classes.mta.js';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
// Configuration options for email sending
export interface IEmailSendOptions {
@ -35,7 +35,7 @@ export interface DeliveryInfo {
}
export class EmailSendJob {
mtaRef: MtaService;
emailServerRef: UnifiedEmailServer;
private email: Email;
private socket: plugins.net.Socket | plugins.tls.TLSSocket = null;
private mxServers: string[] = [];
@ -43,9 +43,9 @@ export class EmailSendJob {
private options: IEmailSendOptions;
public deliveryInfo: DeliveryInfo;
constructor(mtaRef: MtaService, emailArg: Email, options: IEmailSendOptions = {}) {
constructor(emailServerRef: UnifiedEmailServer, emailArg: Email, options: IEmailSendOptions = {}) {
this.email = emailArg;
this.mtaRef = mtaRef;
this.emailServerRef = emailServerRef;
// Set default options
this.options = {
@ -267,25 +267,24 @@ export class EmailSendJob {
// Check if IP warmup is enabled and get an IP to use
let localAddress: string | undefined = undefined;
if (this.mtaRef.config.outbound?.warmup?.enabled) {
const warmupManager = this.mtaRef.getIPWarmupManager();
if (warmupManager) {
const fromDomain = this.email.getFromDomain();
const bestIP = warmupManager.getBestIPForSending({
from: this.email.from,
to: this.email.getAllRecipients(),
domain: fromDomain,
isTransactional: this.email.priority === 'high'
});
try {
const fromDomain = this.email.getFromDomain();
const bestIP = this.emailServerRef.getBestIPForSending({
from: this.email.from,
to: this.email.getAllRecipients(),
domain: fromDomain,
isTransactional: this.email.priority === 'high'
});
if (bestIP) {
this.log(`Using warmed-up IP ${bestIP} for sending`);
localAddress = bestIP;
if (bestIP) {
this.log(`Using warmed-up IP ${bestIP} for sending`);
localAddress = bestIP;
// Record the send for warm-up tracking
warmupManager.recordSend(bestIP);
}
// Record the send for warm-up tracking
this.emailServerRef.recordIPSend(bestIP);
}
} catch (error) {
this.log(`Error selecting IP address: ${error.message}`);
}
// Connect with specified local address if available
@ -471,7 +470,7 @@ export class EmailSendJob {
body += `--${boundary}--\r\n`;
// Create DKIM signature
const dkimSigner = new EmailSignJob(this.mtaRef, {
const dkimSigner = new EmailSignJob(this.emailServerRef, {
domain: this.email.getFromDomain(),
selector: 'mta',
headers: headers,
@ -502,16 +501,6 @@ export class EmailSendJob {
isHardBounce: boolean = false
): void {
try {
// Check if reputation monitoring is enabled
if (!this.mtaRef.config.outbound?.reputation?.enabled) {
return;
}
const reputationMonitor = this.mtaRef.getReputationMonitor();
if (!reputationMonitor) {
return;
}
// Get domain from sender
const domain = this.email.getFromDomain();
if (!domain) {
@ -528,8 +517,8 @@ export class EmailSendJob {
}
}
// Record the event
reputationMonitor.recordSendEvent(domain, {
// Record the event using UnifiedEmailServer
this.emailServerRef.recordReputationEvent(domain, {
type: eventType,
count: 1,
hardBounce: isHardBounce,