import * as plugins from '../plugins.js'; import { Email } from './mta.classes.email.js'; import { EmailSendJob } from './mta.classes.emailsendjob.js'; import { DKIMCreator } from './mta.classes.dkimcreator.js'; import { DKIMVerifier } from './mta.classes.dkimverifier.js'; import { SMTPServer } from './mta.classes.smtpserver.js'; import { DNSManager } from './mta.classes.dnsmanager.js'; import type { SzPlatformService } from '../classes.platformservice.js'; export class MtaService { public platformServiceRef: SzPlatformService; public server: SMTPServer; public dkimCreator: DKIMCreator; public dkimVerifier: DKIMVerifier; public dnsManager: DNSManager; constructor(platformServiceRefArg: SzPlatformService) { this.platformServiceRef = platformServiceRefArg; this.dkimCreator = new DKIMCreator(this); this.dkimVerifier = new DKIMVerifier(this); this.dnsManager = new DNSManager(this); } public async start() { // lets get the certificate /** * gets a certificate for a domain used by a service * @param serviceNameArg * @param domainNameArg */ const typedrouter = new plugins.typedrequest.TypedRouter(); const typedsocketClient = await plugins.typedsocket.TypedSocket.createClient( typedrouter, 'https://cloudly.lossless.one:443' ); const getCertificateForDomainOverHttps = async (domainNameArg: string) => { const typedCertificateRequest = typedsocketClient.createTypedRequest('getSslCertificate'); const typedResponse = await typedCertificateRequest.fire({ authToken: '', // do proper auth here requiredCertName: domainNameArg, }); return typedResponse.certificate; }; const certificate = await getCertificateForDomainOverHttps('mta.lossless.one'); await typedsocketClient.stop(); this.server = new SMTPServer(this, { port: 25, key: certificate.privateKey, cert: certificate.publicKey, }); await this.server.start(); } public async stop() { if (!this.server) { console.error('Server is not running'); return; } await this.server.stop(); } public async send(email: Email): Promise { await this.dkimCreator.handleDKIMKeysForEmail(email); const sendJob = new EmailSendJob(this, email); await sendJob.send(); } }