platformservice/ts/email/email.classes.connector.mailgun.ts

31 lines
913 B
TypeScript
Raw Normal View History

2024-02-15 19:30:38 +00:00
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);
}
}