fix(core): update
This commit is contained in:
66
ts/mta/mta.classes.mta.ts
Normal file
66
ts/mta/mta.classes.mta.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
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';
|
||||
|
||||
export class MTA {
|
||||
public server: SMTPServer;
|
||||
public dkimCreator: DKIMCreator;
|
||||
public dkimVerifier: DKIMVerifier;
|
||||
public dnsManager: DNSManager;
|
||||
|
||||
constructor() {
|
||||
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<any>('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<void> {
|
||||
await this.dkimCreator.handleDKIMKeysForEmail(email);
|
||||
const sendJob = new EmailSendJob(this, email);
|
||||
await sendJob.send();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user