import axios from 'axios'; import { config } from './config'; import { MailSendingError } from './errors/MailErrors'; /** * This class is responsible for all things mail sending. * This uses axios to communicate with the mailer api (https://git.odit.services/lfk/mailer). */ export class Mailer { public static base: string = config.mailer_url; public static key: string = config.mailer_key; /** * Function for sending a password reset mail. * @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. */ 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(); } } }