fix(core): update

This commit is contained in:
2020-08-13 01:37:26 +00:00
parent 0412cecfe5
commit 108f483823
6 changed files with 143 additions and 150 deletions

View File

@ -5,7 +5,7 @@ export class MailgunAccount {
public baseUrl = 'https://api.mailgun.net/v3';
public apiToken: string;
public smartSmtps: {[domain: string]: plugins.smartsmtp.Smartsmtp} = {};
public smartSmtps: { [domain: string]: plugins.smartsmtp.Smartsmtp } = {};
constructor(apiTokenArg: string) {
this.apiToken = apiTokenArg;
@ -15,7 +15,7 @@ export class MailgunAccount {
* allows adding smtp credentials
* Format: [domain]|[username]|[password]
*/
public addSmtpCredentials (credentials: string) {
public addSmtpCredentials(credentials: string) {
const credentialArray = credentials.split('|');
if (credentialArray.length !== 3) {
throw new Error('credentials are in the wrong format');
@ -23,7 +23,7 @@ export class MailgunAccount {
this.smartSmtps[credentialArray[0]] = new plugins.smartsmtp.Smartsmtp({
smtpServer: 'smtp.mailgun.org',
smtpUser: credentialArray[1],
smtpPassword: credentialArray[2]
smtpPassword: credentialArray[2],
});
}
@ -111,21 +111,31 @@ export class MailgunAccount {
console.log('All requirements for API met');
const response = await this.postFormData(`/${domain}/messages`, formFields);
if (response.statusCode === 200) {
console.log(`Sent mail with subject ${smartmailArg.getSubject(dataArg)} to ${toArg} using the mailgun API`);
console.log(
`Sent mail with subject ${smartmailArg.getSubject(
dataArg
)} to ${toArg} using the mailgun API`
);
return response.body;
} else {
console.log(response.body);
throw new Error('could not send email');
}
} else {
console.log('An empty body was provided. This does not work via the API, but using SMTP instead.');
console.log(
'An empty body was provided. This does not work via the API, but using SMTP instead.'
);
const wantedSmartsmtp = this.smartSmtps[domain];
if (!wantedSmartsmtp) {
console.log('did not find appropriate smtp credentials');
return;
}
wantedSmartsmtp.sendSmartMail(smartmailArg, toArg);
console.log(`Sent mail with subject ${smartmailArg.getSubject(dataArg)} to ${toArg} using an smtp transport over Mailgun`);
console.log(
`Sent mail with subject ${smartmailArg.getSubject(
dataArg
)} to ${toArg} using an smtp transport over Mailgun`
);
}
}