31 lines
941 B
TypeScript
31 lines
941 B
TypeScript
import * as plugins from './email.plugins.js';
|
|
import { EmailService } from './email.classes.emailservice.js';
|
|
|
|
export class MailgunConnector {
|
|
public emailRef: EmailService;
|
|
public mailgunAccount: plugins.mailgun.MailgunAccount;
|
|
|
|
constructor(emailRefArg: EmailService) {
|
|
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);
|
|
}
|
|
}
|