31 lines
913 B
TypeScript
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);
|
||
|
}
|
||
|
}
|