2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* SMTP Server Interfaces
|
|
|
|
* Defines all the interfaces used by the SMTP server implementation
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import * as plugins from '../../../plugins.js';
|
|
|
|
import type { Email } from '../../core/classes.email.js';
|
|
|
|
import type { UnifiedEmailServer } from '../../routing/classes.unified.email.server.js';
|
2025-05-22 23:09:41 +00:00
|
|
|
|
2025-05-23 00:06:07 +00:00
|
|
|
// Re-export types from other modules
|
|
|
|
import { SmtpState } from '../interfaces.js';
|
|
|
|
import { SmtpCommand } from './constants.js';
|
|
|
|
export { SmtpState, SmtpCommand };
|
|
|
|
export type { IEnvelopeRecipient } from '../interfaces.js';
|
2025-05-21 12:52:24 +00:00
|
|
|
|
2025-05-22 23:02:37 +00:00
|
|
|
/**
|
|
|
|
* Interface for components that need cleanup
|
|
|
|
*/
|
|
|
|
export interface IDestroyable {
|
|
|
|
/**
|
|
|
|
* Clean up all resources (timers, listeners, etc)
|
|
|
|
*/
|
|
|
|
destroy(): void | Promise<void>;
|
|
|
|
}
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* SMTP authentication credentials
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface ISmtpAuth {
|
2025-05-21 13:42:12 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Username for authentication
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
username: string;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Password for authentication
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
password: string;
|
2025-05-21 13:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* SMTP envelope (sender and recipients)
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
|
|
|
export interface ISmtpEnvelope {
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Mail from address
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
|
|
|
mailFrom: {
|
|
|
|
address: string;
|
2025-05-22 23:02:37 +00:00
|
|
|
args?: Record<string, string>;
|
2025-05-21 13:42:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Recipients list
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
rcptTo: Array<{
|
|
|
|
address: string;
|
|
|
|
args?: Record<string, string>;
|
|
|
|
}>;
|
2025-05-21 13:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* SMTP session representing a client connection
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
|
|
|
export interface ISmtpSession {
|
|
|
|
/**
|
|
|
|
* Unique session identifier
|
|
|
|
*/
|
|
|
|
id: string;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Current state of the SMTP session
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
|
|
|
state: SmtpState;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Client's hostname from EHLO/HELO
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
clientHostname: string | null;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Whether TLS is active for this session
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
secure: boolean;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Authentication status
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
authenticated: boolean;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Authentication username if authenticated
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
username?: string;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
2025-05-22 09:22:55 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Transaction envelope
|
2025-05-22 09:22:55 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
envelope: ISmtpEnvelope;
|
2025-05-22 09:22:55 +00:00
|
|
|
|
2025-05-21 13:42:12 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* When the session was created
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
createdAt: Date;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Last activity timestamp
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-23 00:06:07 +00:00
|
|
|
lastActivity: number;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Client's IP address
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
|
|
|
remoteAddress: string;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Client's port
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
remotePort: number;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Additional session data
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
data?: Record<string, any>;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Message size if SIZE extension is used
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
messageSize?: number;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Server capabilities advertised to client
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
capabilities?: string[];
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Buffer for incomplete data
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
dataBuffer?: string;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Flag to track if we're currently receiving DATA
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
receivingData?: boolean;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* The raw email data being received
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
rawData?: string;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Greeting sent to client
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
greeting?: string;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Whether EHLO has been sent
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
ehloSent?: boolean;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Whether HELO has been sent
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
heloSent?: boolean;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* TLS options for this session
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
tlsOptions?: any;
|
2025-05-23 00:06:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether TLS is being used
|
|
|
|
*/
|
|
|
|
useTLS?: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mail from address for this transaction
|
|
|
|
*/
|
|
|
|
mailFrom?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recipients for this transaction
|
|
|
|
*/
|
|
|
|
rcptTo?: string[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Email data being received
|
|
|
|
*/
|
|
|
|
emailData?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Chunks of email data
|
|
|
|
*/
|
|
|
|
emailDataChunks?: string[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timeout ID for data reception
|
|
|
|
*/
|
|
|
|
dataTimeoutId?: NodeJS.Timeout;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether connection has ended
|
|
|
|
*/
|
|
|
|
connectionEnded?: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Size of email data being received
|
|
|
|
*/
|
|
|
|
emailDataSize?: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processing mode for this session
|
|
|
|
*/
|
|
|
|
processingMode?: string;
|
2025-05-22 23:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Session manager interface
|
|
|
|
*/
|
|
|
|
export interface ISessionManager extends IDestroyable {
|
2025-05-21 13:42:12 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Create a new session for a socket
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-23 00:06:07 +00:00
|
|
|
createSession(socket: plugins.net.Socket | plugins.tls.TLSSocket, secure?: boolean): ISmtpSession;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Get session by socket
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
getSession(socket: plugins.net.Socket | plugins.tls.TLSSocket): ISmtpSession | undefined;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Update session state
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-23 00:06:07 +00:00
|
|
|
updateSessionState(session: ISmtpSession, newState: SmtpState): void;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Remove a session
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
removeSession(socket: plugins.net.Socket | plugins.tls.TLSSocket): void;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Clear all sessions
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
clearAllSessions(): void;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Get all active sessions
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
getAllSessions(): ISmtpSession[];
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Get session count
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
getSessionCount(): number;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Update last activity for a session
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
updateLastActivity(socket: plugins.net.Socket | plugins.tls.TLSSocket): void;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Check for timed out sessions
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
checkTimeouts(timeoutMs: number): ISmtpSession[];
|
2025-05-23 00:06:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update session activity timestamp
|
|
|
|
*/
|
|
|
|
updateSessionActivity(session: ISmtpSession): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace socket in session (for TLS upgrade)
|
|
|
|
*/
|
|
|
|
replaceSocket(oldSocket: plugins.net.Socket | plugins.tls.TLSSocket, newSocket: plugins.net.Socket | plugins.tls.TLSSocket): boolean;
|
2025-05-21 13:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Connection manager interface
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface IConnectionManager extends IDestroyable {
|
2025-05-21 13:42:12 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Handle a new connection
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
handleConnection(socket: plugins.net.Socket | plugins.tls.TLSSocket, secure: boolean): Promise<void>;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Close all active connections
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
closeAllConnections(): void;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Get active connection count
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
getConnectionCount(): number;
|
2025-05-21 13:42:12 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Check if accepting new connections
|
2025-05-21 13:42:12 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
canAcceptConnection(): boolean;
|
2025-05-23 00:06:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle new connection (legacy method name)
|
|
|
|
*/
|
|
|
|
handleNewConnection(socket: plugins.net.Socket): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle new secure connection (legacy method name)
|
|
|
|
*/
|
|
|
|
handleNewSecureConnection(socket: plugins.tls.TLSSocket): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup socket event handlers
|
|
|
|
*/
|
|
|
|
setupSocketEventHandlers(socket: plugins.net.Socket | plugins.tls.TLSSocket): void;
|
2025-05-21 13:42:12 +00:00
|
|
|
}
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Command handler interface
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface ICommandHandler extends IDestroyable {
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Handle an SMTP command
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
handleCommand(
|
|
|
|
socket: plugins.net.Socket | plugins.tls.TLSSocket,
|
|
|
|
command: SmtpCommand,
|
|
|
|
args: string,
|
|
|
|
session: ISmtpSession
|
|
|
|
): Promise<void>;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Get supported commands for current session state
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
getSupportedCommands(session: ISmtpSession): SmtpCommand[];
|
2025-05-23 00:06:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process command (legacy method name)
|
|
|
|
*/
|
|
|
|
processCommand(socket: plugins.net.Socket | plugins.tls.TLSSocket, command: string): Promise<void>;
|
2025-05-22 23:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data handler interface
|
|
|
|
*/
|
|
|
|
export interface IDataHandler extends IDestroyable {
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Handle email data
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
handleData(
|
|
|
|
socket: plugins.net.Socket | plugins.tls.TLSSocket,
|
|
|
|
data: string,
|
|
|
|
session: ISmtpSession
|
|
|
|
): Promise<void>;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Process a complete email
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
processEmail(
|
|
|
|
rawData: string,
|
|
|
|
session: ISmtpSession
|
|
|
|
): Promise<Email>;
|
2025-05-23 00:06:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle data received (legacy method name)
|
|
|
|
*/
|
|
|
|
handleDataReceived(socket: plugins.net.Socket | plugins.tls.TLSSocket, data: string): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process email data (legacy method name)
|
|
|
|
*/
|
|
|
|
processEmailData(socket: plugins.net.Socket | plugins.tls.TLSSocket, data: string): Promise<void>;
|
2025-05-21 12:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* TLS handler interface
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface ITlsHandler extends IDestroyable {
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Handle STARTTLS command
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
handleStartTls(
|
|
|
|
socket: plugins.net.Socket,
|
|
|
|
session: ISmtpSession
|
|
|
|
): Promise<plugins.tls.TLSSocket | null>;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Check if TLS is available
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
isTlsAvailable(): boolean;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Get TLS options
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
getTlsOptions(): plugins.tls.TlsOptions;
|
2025-05-23 00:06:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if TLS is enabled
|
|
|
|
*/
|
|
|
|
isTlsEnabled(): boolean;
|
2025-05-22 23:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Security handler interface
|
|
|
|
*/
|
|
|
|
export interface ISecurityHandler extends IDestroyable {
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Check IP reputation
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
checkIpReputation(socket: plugins.net.Socket | plugins.tls.TLSSocket): Promise<boolean>;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Validate email address
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
isValidEmail(email: string): boolean;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Authenticate user
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
authenticate(auth: ISmtpAuth): Promise<boolean>;
|
2025-05-21 12:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* SMTP server options
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface ISmtpServerOptions {
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Port to listen on
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
port: number;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Hostname of the server
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
hostname: string;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
2025-05-23 00:06:07 +00:00
|
|
|
/**
|
|
|
|
* Host to bind to (optional, defaults to 0.0.0.0)
|
|
|
|
*/
|
|
|
|
host?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Secure port for TLS connections
|
|
|
|
*/
|
|
|
|
securePort?: number;
|
|
|
|
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* TLS/SSL private key (PEM format)
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
key?: string;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* TLS/SSL certificate (PEM format)
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
cert?: string;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* CA certificates for TLS (PEM format)
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
ca?: string;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Maximum size of messages in bytes
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
maxSize?: number;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Maximum number of concurrent connections
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
maxConnections?: number;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Authentication options
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
auth?: {
|
|
|
|
/**
|
|
|
|
* Whether authentication is required
|
|
|
|
*/
|
|
|
|
required: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allowed authentication methods
|
|
|
|
*/
|
|
|
|
methods: ('PLAIN' | 'LOGIN' | 'OAUTH2')[];
|
|
|
|
};
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Socket timeout in milliseconds (default: 5 minutes / 300000ms)
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
socketTimeout?: number;
|
|
|
|
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Initial connection timeout in milliseconds (default: 30 seconds / 30000ms)
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
connectionTimeout?: number;
|
2025-05-22 09:22:55 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Interval for checking idle sessions in milliseconds (default: 5 seconds / 5000ms)
|
|
|
|
* For testing, can be set lower (e.g. 1000ms) to detect timeouts more quickly
|
2025-05-22 09:22:55 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
cleanupInterval?: number;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Maximum number of recipients allowed per message (default: 100)
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
maxRecipients?: number;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Maximum message size in bytes (default: 10MB / 10485760 bytes)
|
|
|
|
* This is advertised in the EHLO SIZE extension
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
size?: number;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Timeout for the DATA command in milliseconds (default: 60000ms / 1 minute)
|
|
|
|
* This controls how long to wait for the complete email data
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
dataTimeout?: number;
|
2025-05-21 12:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Result of SMTP transaction
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface ISmtpTransactionResult {
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Whether the transaction was successful
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
success: boolean;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Error message if failed
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
error?: string;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Message ID if successful
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
messageId?: string;
|
2025-05-21 12:52:24 +00:00
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Resulting email if successful
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
email?: Email;
|
2025-05-21 12:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Interface for SMTP session events
|
|
|
|
* These events are emitted by the session manager
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface ISessionEvents {
|
|
|
|
created: (session: ISmtpSession, socket: plugins.net.Socket | plugins.tls.TLSSocket) => void;
|
|
|
|
stateChanged: (session: ISmtpSession, previousState: SmtpState, newState: SmtpState) => void;
|
|
|
|
timeout: (session: ISmtpSession, socket: plugins.net.Socket | plugins.tls.TLSSocket) => void;
|
|
|
|
completed: (session: ISmtpSession, socket: plugins.net.Socket | plugins.tls.TLSSocket) => void;
|
|
|
|
error: (session: ISmtpSession, error: Error) => void;
|
2025-05-21 12:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* SMTP Server interface
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
2025-05-22 23:02:37 +00:00
|
|
|
export interface ISmtpServer extends IDestroyable {
|
2025-05-21 12:52:24 +00:00
|
|
|
/**
|
|
|
|
* Start the SMTP server
|
|
|
|
*/
|
|
|
|
listen(): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the SMTP server
|
|
|
|
*/
|
|
|
|
close(): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the session manager
|
|
|
|
*/
|
|
|
|
getSessionManager(): ISessionManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the connection manager
|
|
|
|
*/
|
|
|
|
getConnectionManager(): IConnectionManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the command handler
|
|
|
|
*/
|
|
|
|
getCommandHandler(): ICommandHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data handler
|
|
|
|
*/
|
|
|
|
getDataHandler(): IDataHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the TLS handler
|
|
|
|
*/
|
|
|
|
getTlsHandler(): ITlsHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the security handler
|
|
|
|
*/
|
|
|
|
getSecurityHandler(): ISecurityHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the server options
|
|
|
|
*/
|
|
|
|
getOptions(): ISmtpServerOptions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the email server reference
|
|
|
|
*/
|
|
|
|
getEmailServer(): UnifiedEmailServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Configuration for creating SMTP server
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
export interface ISmtpServerConfig {
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Email server instance
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
emailServer: UnifiedEmailServer;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Server options
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
options: ISmtpServerOptions;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Optional custom session manager
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
sessionManager?: ISessionManager;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Optional custom connection manager
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
connectionManager?: IConnectionManager;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Optional custom command handler
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
commandHandler?: ICommandHandler;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Optional custom data handler
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
dataHandler?: IDataHandler;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Optional custom TLS handler
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
tlsHandler?: ITlsHandler;
|
|
|
|
|
|
|
|
/**
|
2025-05-22 23:02:37 +00:00
|
|
|
* Optional custom security handler
|
2025-05-21 12:52:24 +00:00
|
|
|
*/
|
|
|
|
securityHandler?: ISecurityHandler;
|
|
|
|
}
|