Files
smartmta/dist_ts/mail/delivery/classes.smtp.client.legacy.d.ts

276 lines
6.0 KiB
TypeScript
Raw Normal View History

2026-02-10 15:54:09 +00:00
import { Email } from '../core/classes.email.js';
import type { EmailProcessingMode } from './interfaces.js';
/**
* SMTP client connection options
*/
export type ISmtpClientOptions = {
/**
* Hostname of the SMTP server
*/
host: string;
/**
* Port to connect to
*/
port: number;
/**
* Whether to use TLS for the connection
*/
secure?: boolean;
/**
* Connection timeout in milliseconds
*/
connectionTimeout?: number;
/**
* Socket timeout in milliseconds
*/
socketTimeout?: number;
/**
* Command timeout in milliseconds
*/
commandTimeout?: number;
/**
* TLS options
*/
tls?: {
/**
* Whether to verify certificates
*/
rejectUnauthorized?: boolean;
/**
* Minimum TLS version
*/
minVersion?: string;
/**
* CA certificate path
*/
ca?: string;
};
/**
* Authentication options
*/
auth?: {
/**
* Authentication user
*/
user: string;
/**
* Authentication password
*/
pass: string;
/**
* Authentication method
*/
method?: 'PLAIN' | 'LOGIN' | 'OAUTH2';
};
/**
* Domain name for EHLO
*/
domain?: string;
/**
* DKIM options for signing outgoing emails
*/
dkim?: {
/**
* Whether to sign emails with DKIM
*/
enabled: boolean;
/**
* Domain name for DKIM
*/
domain: string;
/**
* Selector for DKIM
*/
selector: string;
/**
* Private key for DKIM signing
*/
privateKey: string;
/**
* Headers to sign
*/
headers?: string[];
};
};
/**
* SMTP delivery result
*/
export type ISmtpDeliveryResult = {
/**
* Whether the delivery was successful
*/
success: boolean;
/**
* Message ID if successful
*/
messageId?: string;
/**
* Error message if failed
*/
error?: string;
/**
* SMTP response code
*/
responseCode?: string;
/**
* Recipients successfully delivered to
*/
acceptedRecipients: string[];
/**
* Recipients rejected during delivery
*/
rejectedRecipients: string[];
/**
* Server response
*/
response?: string;
/**
* Timestamp of the delivery attempt
*/
timestamp: number;
/**
* Whether DKIM signing was applied
*/
dkimSigned?: boolean;
/**
* Whether this was a TLS secured delivery
*/
secure?: boolean;
/**
* Whether authentication was used
*/
authenticated?: boolean;
};
/**
* SMTP client for sending emails to remote mail servers
*/
export declare class SmtpClient {
private options;
private connected;
private socket?;
private supportedExtensions;
/**
* Create a new SMTP client instance
* @param options SMTP client connection options
*/
constructor(options: ISmtpClientOptions);
/**
* Connect to the SMTP server
*/
connect(): Promise<void>;
/**
* Send EHLO command to the server
*/
private sendEhlo;
/**
* Start TLS negotiation
*/
private startTls;
/**
* Upgrade socket to TLS
* @param socket Original socket
*/
private upgradeTls;
/**
* Authenticate with the server
*/
private authenticate;
/**
* Authenticate using PLAIN method
* @param user Username
* @param pass Password
*/
private authPlain;
/**
* Authenticate using LOGIN method
* @param user Username
* @param pass Password
*/
private authLogin;
/**
* Authenticate using OAuth2 method
* @param user Username
* @param token OAuth2 token
*/
private authOAuth2;
/**
* Send an email through the SMTP client
* @param email Email to send
* @param processingMode Optional processing mode
*/
sendMail(email: Email, processingMode?: EmailProcessingMode): Promise<ISmtpDeliveryResult>;
/**
* Apply DKIM signature to email
* @param email Email to sign
*/
private applyDkimSignature;
/**
* Format email for SMTP transmission
* @param email Email to format
*/
private getFormattedEmail;
/**
* Get size of email in bytes
* @param email Email to measure
*/
private getEmailSize;
/**
* Send SMTP command and wait for response
* @param command SMTP command to send
*/
private commandQueue;
private processingCommands;
private supportsPipelining;
/**
* Send an SMTP command and wait for response
* @param command SMTP command to send
* @param allowPipelining Whether this command can be pipelined
*/
private sendCommand;
/**
* Process the command queue - either one by one or pipelined if supported
*/
private processCommandQueue;
/**
* Process the next command in the queue (non-pipelined mode)
*/
private processNextCommand;
/**
* Process responses for pipelined commands
*/
private processResponses;
/**
* Read response from the server
*/
private readResponse;
/**
* Check if the response is complete
* @param response Response to check
*/
private isCompleteResponse;
/**
* Check if the response is an error
* @param response Response to check
*/
private isErrorResponse;
/**
* Create appropriate error from response
* @param response Error response
* @param code SMTP status code
*/
private createErrorFromResponse;
/**
* Close the connection to the server
*/
close(): Promise<void>;
/**
* Checks if the connection is active
*/
isConnected(): boolean;
/**
* Update SMTP client options
* @param options New options
*/
updateOptions(options: Partial<ISmtpClientOptions>): void;
}