dcrouter/ts/mail/delivery/classes.smtp.client.ts
2025-05-22 10:18:02 +00:00

111 lines
2.9 KiB
TypeScript

/**
* SMTP Client - Legacy Compatibility Facade
*
* @deprecated This file provides backward compatibility for the legacy SmtpClient class.
* New code should use the modular implementation from smtpclient/ directory.
*
* Migration Guide:
* - Replace `new SmtpClient(options)` with `createSmtpClient(options)`
* - Import from `'./smtpclient/index.js'` instead of `'./classes.smtp.client.js'`
* - The new API is fully compatible with the legacy interface
*/
import { createSmtpClient } from './smtpclient/index.js';
import type {
ISmtpClientOptions as ModularOptions,
ISmtpSendResult,
IConnectionPoolStatus
} from './smtpclient/interfaces.js';
import type { SmtpClient as ModularSmtpClient } from './smtpclient/smtp-client.js';
import type { Email } from '../core/classes.email.js';
// Re-export the new interfaces for compatibility
export type { ISmtpSendResult, IConnectionPoolStatus };
/**
* Legacy SMTP client options interface
* @deprecated Use ISmtpClientOptions from smtpclient/interfaces.js
*/
export type ISmtpClientOptions = ModularOptions;
/**
* Legacy SMTP Client class - Compatibility Facade
*
* This class wraps the new modular implementation to maintain backward compatibility.
* All method calls are delegated to the new implementation.
*
* @deprecated Use createSmtpClient() factory function instead
*/
export class SmtpClient {
private client: ModularSmtpClient;
constructor(options: ISmtpClientOptions) {
// Create the new modular client
this.client = createSmtpClient(options);
}
/**
* Send an email
*/
public async sendMail(email: Email): Promise<ISmtpSendResult> {
return this.client.sendMail(email);
}
/**
* Test connection to SMTP server
*/
public async verify(): Promise<boolean> {
return this.client.verify();
}
/**
* Check if client is connected
*/
public isConnected(): boolean {
return this.client.isConnected();
}
/**
* Get connection pool status
*/
public getPoolStatus(): IConnectionPoolStatus {
return this.client.getPoolStatus();
}
/**
* Update client options
*/
public updateOptions(newOptions: Partial<ISmtpClientOptions>): void {
return this.client.updateOptions(newOptions);
}
/**
* Close all connections and shutdown client
*/
public async close(): Promise<void> {
return this.client.close();
}
/**
* Add event listener (delegate to internal client)
*/
public on(event: string, listener: (...args: any[]) => void): this {
this.client.on(event, listener);
return this;
}
/**
* Remove event listener (delegate to internal client)
*/
public off(event: string, listener: (...args: any[]) => void): this {
this.client.off(event, listener);
return this;
}
/**
* Emit event (delegate to internal client)
*/
public emit(event: string, ...args: any[]): boolean {
return this.client.emit(event, ...args);
}
}