dcrouter/ts/mail/delivery/classes.smtp.client.ts

111 lines
2.9 KiB
TypeScript
Raw Normal View History

2025-05-21 02:17:18 +00:00
/**
2025-05-22 10:18:02 +00:00
* 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
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
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 };
2025-05-21 02:17:18 +00:00
/**
2025-05-22 10:18:02 +00:00
* Legacy SMTP client options interface
* @deprecated Use ISmtpClientOptions from smtpclient/interfaces.js
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
export type ISmtpClientOptions = ModularOptions;
2025-05-21 02:17:18 +00:00
/**
2025-05-22 10:18:02 +00:00
* 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
2025-05-21 02:17:18 +00:00
*/
export class SmtpClient {
2025-05-22 10:18:02 +00:00
private client: ModularSmtpClient;
2025-05-21 02:17:18 +00:00
constructor(options: ISmtpClientOptions) {
2025-05-22 10:18:02 +00:00
// Create the new modular client
this.client = createSmtpClient(options);
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Send an email
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public async sendMail(email: Email): Promise<ISmtpSendResult> {
return this.client.sendMail(email);
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Test connection to SMTP server
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public async verify(): Promise<boolean> {
return this.client.verify();
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Check if client is connected
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public isConnected(): boolean {
return this.client.isConnected();
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Get connection pool status
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public getPoolStatus(): IConnectionPoolStatus {
return this.client.getPoolStatus();
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Update client options
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public updateOptions(newOptions: Partial<ISmtpClientOptions>): void {
return this.client.updateOptions(newOptions);
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Close all connections and shutdown client
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public async close(): Promise<void> {
return this.client.close();
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Add event listener (delegate to internal client)
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public on(event: string, listener: (...args: any[]) => void): this {
this.client.on(event, listener);
return this;
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Remove event listener (delegate to internal client)
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public off(event: string, listener: (...args: any[]) => void): this {
this.client.off(event, listener);
return this;
2025-05-21 02:17:18 +00:00
}
/**
2025-05-22 10:18:02 +00:00
* Emit event (delegate to internal client)
2025-05-21 02:17:18 +00:00
*/
2025-05-22 10:18:02 +00:00
public emit(event: string, ...args: any[]): boolean {
return this.client.emit(event, ...args);
2025-05-21 02:17:18 +00:00
}
}