parent
f289afd8bc
commit
1551a444ba
@ -1,34 +1,41 @@
|
|||||||
|
import axios from 'axios';
|
||||||
import { config } from './config';
|
import { config } from './config';
|
||||||
|
import { MailSendingError } from './errors/MailErrors';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for all things mail sending.
|
* This class is responsible for all things mail sending.
|
||||||
* This uses the mail emplates from src/static/mail_templates
|
* This uses the mail emplates from src/static/mail_templates
|
||||||
*/
|
*/
|
||||||
export class Mailer {
|
export class Mailer {
|
||||||
|
public static base: string = config.mailer_url;
|
||||||
/**
|
public static key: string = config.mailer_key;
|
||||||
* The class's default constructor.
|
|
||||||
* Creates the transporter and tests the connection.
|
|
||||||
*/
|
|
||||||
constructor() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function for sending a test mail from the test mail template.
|
* Function for sending a test mail from the test mail template.
|
||||||
* @param to_address The address the mail will be sent to. Should always get pulled from a user object.
|
* @param to_address The address the mail will be sent to. Should always get pulled from a user object.
|
||||||
* @param token The requested password reset token - will be combined with the app_url to generate a password reset link.
|
* @param token The requested password reset token - will be combined with the app_url to generate a password reset link.
|
||||||
*/
|
*/
|
||||||
public async sendResetMail(to_address: string, token: string) {
|
public static async sendResetMail(to_address: string, token: string, locale: string = "en") {
|
||||||
|
try {
|
||||||
|
await axios.post(`${Mailer.base}/reset?locale=${locale}&key=${Mailer.key}`, {
|
||||||
|
address: to_address,
|
||||||
|
resetKey: token
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new MailSendingError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function for sending a test mail from the test mail template.
|
* Function for sending a test mail from the test mail template.
|
||||||
* @param to_address The address the test mail will be sent to - this is the configured from-address by default.
|
* @param to_address The address the test mail will be sent to - this is the configured from-address by default.
|
||||||
*/
|
*/
|
||||||
public async sendTestMail(to_address: string = config.mail_from) {
|
public static async sendTestMail(locale: string = "en") {
|
||||||
|
try {
|
||||||
|
await axios.post(`${Mailer.base}/test?locale=${locale}&key=${Mailer.key}`);
|
||||||
|
} catch (error) {
|
||||||
|
throw new MailSendingError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user