update
This commit is contained in:
@ -49,9 +49,9 @@ export async function startTestServer(config: ITestServerConfig): Promise<ITestS
|
||||
}
|
||||
} as any;
|
||||
|
||||
// Load test certificates if TLS is enabled
|
||||
let key: string | undefined;
|
||||
let cert: string | undefined;
|
||||
// Load test certificates
|
||||
let key: string;
|
||||
let cert: string;
|
||||
|
||||
if (serverConfig.tlsEnabled) {
|
||||
try {
|
||||
@ -89,6 +89,34 @@ export async function startTestServer(config: ITestServerConfig): Promise<ITestS
|
||||
cert = pki.certificateToPem(certificate);
|
||||
key = pki.privateKeyToPem(keys.privateKey);
|
||||
}
|
||||
} else {
|
||||
// Always provide a self-signed certificate for non-TLS servers
|
||||
// This is required by the interface
|
||||
const forge = await import('node-forge');
|
||||
const pki = forge.pki;
|
||||
|
||||
// Generate key pair
|
||||
const keys = pki.rsa.generateKeyPair(2048);
|
||||
|
||||
// Create certificate
|
||||
const certificate = pki.createCertificate();
|
||||
certificate.publicKey = keys.publicKey;
|
||||
certificate.serialNumber = '01';
|
||||
certificate.validity.notBefore = new Date();
|
||||
certificate.validity.notAfter = new Date();
|
||||
certificate.validity.notAfter.setFullYear(certificate.validity.notBefore.getFullYear() + 1);
|
||||
|
||||
const attrs = [{
|
||||
name: 'commonName',
|
||||
value: serverConfig.hostname
|
||||
}];
|
||||
certificate.setSubject(attrs);
|
||||
certificate.setIssuer(attrs);
|
||||
certificate.sign(keys.privateKey);
|
||||
|
||||
// Convert to PEM
|
||||
cert = pki.certificateToPem(certificate);
|
||||
key = pki.privateKeyToPem(keys.privateKey);
|
||||
}
|
||||
|
||||
// SMTP server options
|
||||
@ -103,7 +131,10 @@ export async function startTestServer(config: ITestServerConfig): Promise<ITestS
|
||||
socketTimeout: serverConfig.timeout,
|
||||
connectionTimeout: serverConfig.timeout * 2,
|
||||
cleanupInterval: 300000,
|
||||
auth: serverConfig.authRequired
|
||||
auth: serverConfig.authRequired ? {
|
||||
required: true,
|
||||
methods: ['PLAIN', 'LOGIN'] as ('PLAIN' | 'LOGIN' | 'OAUTH2')[]
|
||||
} : undefined
|
||||
};
|
||||
|
||||
// Create SMTP server
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { SmtpClient } from '../../ts/mail/delivery/classes.smtp.client.js';
|
||||
import type { ISmtpClientOptions } from '../../ts/mail/delivery/smtpclient/interfaces.js';
|
||||
import { Email } from '../../ts/mail/core/classes.email.js';
|
||||
|
||||
/**
|
||||
* Create a test SMTP client
|
||||
@ -10,18 +11,11 @@ export function createTestSmtpClient(options: Partial<ISmtpClientOptions> = {}):
|
||||
port: options.port || 2525,
|
||||
secure: options.secure || false,
|
||||
auth: options.auth,
|
||||
ignoreTLS: options.ignoreTLS || true,
|
||||
requireTLS: options.requireTLS || false,
|
||||
connectionTimeout: options.connectionTimeout || 5000,
|
||||
socketTimeout: options.socketTimeout || 5000,
|
||||
greetingTimeout: options.greetingTimeout || 5000,
|
||||
maxConnections: options.maxConnections || 5,
|
||||
maxMessages: options.maxMessages || 100,
|
||||
rateDelta: options.rateDelta || 1000,
|
||||
rateLimit: options.rateLimit || 5,
|
||||
logger: options.logger || false,
|
||||
debug: options.debug || false,
|
||||
authMethod: options.authMethod || 'PLAIN',
|
||||
tls: options.tls || {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
@ -51,7 +45,14 @@ export async function sendTestEmail(
|
||||
html: options.html
|
||||
};
|
||||
|
||||
return client.sendMail(mailOptions);
|
||||
const email = new Email({
|
||||
from: mailOptions.from,
|
||||
to: mailOptions.to,
|
||||
subject: mailOptions.subject,
|
||||
text: mailOptions.text,
|
||||
html: mailOptions.html
|
||||
});
|
||||
return client.sendMail(email);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,11 +96,10 @@ export function createAuthenticatedClient(
|
||||
port,
|
||||
auth: {
|
||||
user: username,
|
||||
pass: password
|
||||
pass: password,
|
||||
method: authMethod
|
||||
},
|
||||
authMethod,
|
||||
secure: false,
|
||||
ignoreTLS: true
|
||||
secure: false
|
||||
});
|
||||
}
|
||||
|
||||
@ -111,7 +111,6 @@ export function createTlsClient(
|
||||
port: number,
|
||||
options: {
|
||||
secure?: boolean;
|
||||
requireTLS?: boolean;
|
||||
rejectUnauthorized?: boolean;
|
||||
} = {}
|
||||
): SmtpClient {
|
||||
@ -119,8 +118,6 @@ export function createTlsClient(
|
||||
host,
|
||||
port,
|
||||
secure: options.secure || false,
|
||||
requireTLS: options.requireTLS || false,
|
||||
ignoreTLS: false,
|
||||
tls: {
|
||||
rejectUnauthorized: options.rejectUnauthorized || false
|
||||
}
|
||||
|
Reference in New Issue
Block a user