platformservice/ts/email/email.classes.connector.mailgun.ts
2024-02-15 20:30:38 +01:00

31 lines
913 B
TypeScript

import * as plugins from './email.plugins.js';
import { Email } from './email.classes.email.js';
export class MailgunConnector {
public emailRef: Email;
public mailgunAccount: plugins.mailgun.MailgunAccount;
constructor(emailRefArg: Email) {
this.emailRef = emailRefArg;
this.mailgunAccount = new plugins.mailgun.MailgunAccount({
apiToken: this.emailRef.qenv.getEnvVarOnDemand('MAILGUN_API_TOKEN'),
region: 'eu',
});
this.mailgunAccount.addSmtpCredentials(
this.emailRef.qenv.getEnvVarOnDemand('MAILGUN_SMTP_CREDENTIALS')
);
}
public async sendEmail(
smartMailArg: plugins.smartmail.Smartmail<any>,
toArg: string,
dataArg: any = {}
) {
this.mailgunAccount.sendSmartMail(smartMailArg, toArg, dataArg);
}
public async receiveEmail(messageUrl: string) {
return await this.mailgunAccount.retrieveSmartMailFromMessageUrl(messageUrl);
}
}