Added function for sending test mail
This commit is contained in:
parent
87d7175f96
commit
602600db89
@ -63,16 +63,16 @@ export class Mailer {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 token The requested password reset token - will be combined with the app_url to generate a password reset link.
|
||||
*/
|
||||
* 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 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, locale: string = "en") {
|
||||
await i18next.changeLanguage(locale);
|
||||
|
||||
const reset_link = `${config.app_url}/reset/${(Buffer.from(token)).toString("base64")}`
|
||||
const template_html = Handlebars.compile(fs.readFileSync(__dirname + '/static/mail_templates/pw-reset.html', { encoding: 'utf8' }));
|
||||
const template_txt = Handlebars.compile(fs.readFileSync(__dirname + '/static/mail_templates/pw-reset.html', { encoding: 'utf8' }));
|
||||
const template_html = Handlebars.compile(fs.readFileSync(__dirname + '/templates/pw-reset.html', { encoding: 'utf8' }));
|
||||
const template_txt = Handlebars.compile(fs.readFileSync(__dirname + '/templates/pw-reset.txt', { encoding: 'utf8' }));
|
||||
const body_html = template_html({ recipient_mail: to_address, copyright_owner: config.copyright_owner, link_imprint: `${config.app_url}/imprint`, link_privacy: `${config.app_url}/privacy`, reset_link });
|
||||
const body_txt = template_txt({ recipient_mail: to_address, copyright_owner: config.copyright_owner, link_imprint: `${config.app_url}/imprint`, link_privacy: `${config.app_url}/privacy`, reset_link });
|
||||
|
||||
@ -85,6 +85,29 @@ export class Mailer {
|
||||
await this.sendMail(mail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 token The requested password reset token - will be combined with the app_url to generate a password reset link.
|
||||
*/
|
||||
public async sendTestMail(to_address: string = config.mail_from, locale: string = "en") {
|
||||
await i18next.changeLanguage(locale);
|
||||
|
||||
const template_html = Handlebars.compile(fs.readFileSync(__dirname + '/templates/test.html', { encoding: 'utf8' }));
|
||||
const template_txt = Handlebars.compile(fs.readFileSync(__dirname + '/templates/test.txt', { encoding: 'utf8' }));
|
||||
const body_html = template_html({ recipient_mail: to_address, copyright_owner: config.copyright_owner, link_imprint: `${config.app_url}/imprint`, link_privacy: `${config.app_url}/privacy` });
|
||||
const body_txt = template_txt({ recipient_mail: to_address, copyright_owner: config.copyright_owner, link_imprint: `${config.app_url}/imprint`, link_privacy: `${config.app_url}/privacy` });
|
||||
|
||||
fs.writeFileSync("./test.tmp", body_txt);
|
||||
const mail: MailOptions = {
|
||||
to: to_address,
|
||||
subject: i18next.t("subject_reset", Mailer.interpolations).toString(),
|
||||
text: body_txt,
|
||||
html: body_html
|
||||
};
|
||||
await this.sendMail(mail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function for sending a mail via this object's transporter.
|
||||
* @param mail MailOptions object containing the
|
||||
|
Loading…
x
Reference in New Issue
Block a user