update
This commit is contained in:
71
ts/mail/delivery/classes.mta.config.ts
Normal file
71
ts/mail/delivery/classes.mta.config.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import * as plugins from '../../plugins.js';
|
||||
import * as paths from '../../paths.js';
|
||||
import type { SzPlatformService } from '../../classes.platformservice.js';
|
||||
|
||||
/**
|
||||
* Configures MTA storage settings for the platform service
|
||||
* @param platformService Reference to the platform service
|
||||
* @param options Configuration options containing storage paths
|
||||
*/
|
||||
export function configureMtaStorage(platformService: SzPlatformService, options: any): void {
|
||||
// Extract the receivedEmailsPath if available
|
||||
if (options?.emailPortConfig?.receivedEmailsPath) {
|
||||
const receivedEmailsPath = options.emailPortConfig.receivedEmailsPath;
|
||||
|
||||
// Ensure the directory exists
|
||||
plugins.smartfile.fs.ensureDirSync(receivedEmailsPath);
|
||||
|
||||
// Apply configuration to MTA service if available
|
||||
if (platformService.mtaService) {
|
||||
platformService.mtaService.configure({
|
||||
storagePath: receivedEmailsPath
|
||||
});
|
||||
|
||||
console.log(`Configured MTA to store received emails to: ${receivedEmailsPath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure MTA service with port and storage settings
|
||||
* @param platformService Reference to the platform service
|
||||
* @param config Configuration settings for MTA
|
||||
*/
|
||||
export function configureMtaService(
|
||||
platformService: SzPlatformService,
|
||||
config: {
|
||||
port?: number;
|
||||
host?: string;
|
||||
secure?: boolean;
|
||||
storagePath?: string;
|
||||
}
|
||||
): boolean {
|
||||
if (!platformService?.mtaService) {
|
||||
console.error('MTA service not available in platform service');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configure MTA with the provided port
|
||||
const mtaConfig = {
|
||||
port: config.port, // Use the port provided by the config
|
||||
host: config.host || 'localhost',
|
||||
secure: config.secure || false,
|
||||
storagePath: config.storagePath
|
||||
};
|
||||
|
||||
// Configure the MTA service
|
||||
platformService.mtaService.configure(mtaConfig);
|
||||
|
||||
console.log(`Configured MTA service on port ${mtaConfig.port}`);
|
||||
|
||||
// Set up storage path if provided
|
||||
if (config.storagePath) {
|
||||
configureMtaStorage(platformService, {
|
||||
emailPortConfig: {
|
||||
receivedEmailsPath: config.storagePath
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user