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

31 lines
941 B
TypeScript
Raw Normal View History

2024-02-15 19:30:38 +00:00
import * as plugins from './email.plugins.js';
2024-02-16 12:28:40 +00:00
import { EmailService } from './email.classes.emailservice.js';
2024-02-15 19:30:38 +00:00
export class MailgunConnector {
2024-02-16 12:28:40 +00:00
public emailRef: EmailService;
2024-02-15 19:30:38 +00:00
public mailgunAccount: plugins.mailgun.MailgunAccount;
2024-02-16 12:28:40 +00:00
constructor(emailRefArg: EmailService) {
2024-02-15 19:30:38 +00:00
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);
}
}