parent
a62f9c683d
commit
4994cb0489
@ -16,7 +16,7 @@ import { MailServerConfigError } from './errors/MailErrors';
|
|||||||
*/
|
*/
|
||||||
export class Mailer {
|
export class Mailer {
|
||||||
private transport: Mail;
|
private transport: Mail;
|
||||||
private static interpolations = { copyright_owner: config.copyright_owner }
|
private static interpolations = { copyright_owner: config.copyright_owner, event_name: config.event_name, contact_mail: config.contact_mail }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main constructor.
|
* Main constructor.
|
||||||
@ -69,11 +69,18 @@ export class Mailer {
|
|||||||
public async sendResetMail(to_address: string, token: string, locale: string = "en") {
|
public async sendResetMail(to_address: string, token: string, locale: string = "en") {
|
||||||
await i18next.changeLanguage(locale);
|
await i18next.changeLanguage(locale);
|
||||||
|
|
||||||
const reset_link = `${config.app_url}/reset/${(Buffer.from(token)).toString("base64")}`
|
const replacements = {
|
||||||
|
recipient_mail: to_address,
|
||||||
|
copyright_owner: config.copyright_owner,
|
||||||
|
link_imprint: `${config.app_url}/imprint`,
|
||||||
|
link_privacy: `${config.app_url}/privacy`,
|
||||||
|
reset_link: `${config.app_url}/reset/${(Buffer.from(token)).toString("base64")}`
|
||||||
|
}
|
||||||
|
|
||||||
const template_html = Handlebars.compile(fs.readFileSync(__dirname + '/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 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_html = template_html(replacements);
|
||||||
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 });
|
const body_txt = template_txt(replacements);
|
||||||
|
|
||||||
const mail: MailOptions = {
|
const mail: MailOptions = {
|
||||||
to: to_address,
|
to: to_address,
|
||||||
@ -91,13 +98,18 @@ export class Mailer {
|
|||||||
public async sendTestMail(locale: string = "en") {
|
public async sendTestMail(locale: string = "en") {
|
||||||
await i18next.changeLanguage(locale);
|
await i18next.changeLanguage(locale);
|
||||||
const to_address: string = config.mail_from;
|
const to_address: string = config.mail_from;
|
||||||
|
const replacements = {
|
||||||
|
recipient_mail: to_address,
|
||||||
|
copyright_owner: config.copyright_owner,
|
||||||
|
link_imprint: `${config.app_url}/imprint`,
|
||||||
|
link_privacy: `${config.app_url}/privacy`
|
||||||
|
}
|
||||||
|
|
||||||
const template_html = Handlebars.compile(fs.readFileSync(__dirname + '/templates/test.html', { encoding: 'utf8' }));
|
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 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_html = template_html(replacements);
|
||||||
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` });
|
const body_txt = template_txt(replacements);
|
||||||
|
|
||||||
fs.writeFileSync("./test.tmp", body_txt);
|
|
||||||
const mail: MailOptions = {
|
const mail: MailOptions = {
|
||||||
to: to_address,
|
to: to_address,
|
||||||
subject: i18next.t("test-mail", Mailer.interpolations).toString(),
|
subject: i18next.t("test-mail", Mailer.interpolations).toString(),
|
||||||
@ -107,6 +119,39 @@ export class Mailer {
|
|||||||
await this.sendMail(mail);
|
await this.sendMail(mail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function for sending a reset mail from the reset 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 sendWelcomeMail(to_address: string, token: string, locale: string = "en") {
|
||||||
|
await i18next.changeLanguage(locale);
|
||||||
|
|
||||||
|
const replacements = {
|
||||||
|
recipient_mail: to_address,
|
||||||
|
copyright_owner: config.copyright_owner,
|
||||||
|
link_imprint: `${config.app_url}/imprint`,
|
||||||
|
link_privacy: `${config.app_url}/privacy`,
|
||||||
|
selfservice_link: `${config.app_url}/selfservice/profile/${token}`,
|
||||||
|
forgot_link: `${config.app_url}/selfservice`,
|
||||||
|
contact_mail: config.contact_mail,
|
||||||
|
event_name: config.event_name
|
||||||
|
}
|
||||||
|
|
||||||
|
const template_html = Handlebars.compile(fs.readFileSync(__dirname + '/templates/welcome_runner.html', { encoding: 'utf8' }));
|
||||||
|
const template_txt = Handlebars.compile(fs.readFileSync(__dirname + '/templates/welcome_runner.txt', { encoding: 'utf8' }));
|
||||||
|
const body_html = template_html(replacements);
|
||||||
|
const body_txt = template_txt(replacements);
|
||||||
|
|
||||||
|
const mail: MailOptions = {
|
||||||
|
to: to_address,
|
||||||
|
subject: i18next.t("event_name-registration", Mailer.interpolations).toString(),
|
||||||
|
text: body_txt,
|
||||||
|
html: body_html
|
||||||
|
};
|
||||||
|
await this.sendMail(mail);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper function for sending a mail via this object's transporter.
|
* Wrapper function for sending a mail via this object's transporter.
|
||||||
* @param mail MailOptions object containing the
|
* @param mail MailOptions object containing the
|
||||||
|
@ -16,7 +16,8 @@ export const config = {
|
|||||||
privacy_url: process.env.PRIVACY_URL || "/privacy",
|
privacy_url: process.env.PRIVACY_URL || "/privacy",
|
||||||
imprint_url: process.env.IMPRINT_URL || "/imprint",
|
imprint_url: process.env.IMPRINT_URL || "/imprint",
|
||||||
copyright_owner: process.env.COPYRIGHT_OWNER || "LfK!",
|
copyright_owner: process.env.COPYRIGHT_OWNER || "LfK!",
|
||||||
event_name: process.env.EVENT_NAME || "Testing 4 Kaya!"
|
event_name: process.env.EVENT_NAME || "Testing 4 Kaya!",
|
||||||
|
contact_mail: process.env.CONTACT_MAIL || process.env.MAIL_FROM,
|
||||||
}
|
}
|
||||||
let errors = 0
|
let errors = 0
|
||||||
if (typeof config.internal_port !== "number") {
|
if (typeof config.internal_port !== "number") {
|
||||||
|
@ -322,7 +322,7 @@
|
|||||||
<table align="left" border="0" cellpadding="0" cellspacing="0" role="presentation">
|
<table align="left" border="0" cellpadding="0" cellspacing="0" role="presentation">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="s-btn s-btn__primary" style="border-radius: 4px; background: #0095ff;">
|
<td class="s-btn s-btn__primary" style="border-radius: 4px; background: #0095ff;">
|
||||||
<a class="s-btn s-btn__primary" href="{{selfservice_url}}" target="_parent" style="background: #0095FF; border: 1px solid #0077cc; box-shadow: inset 0 1px 0 0 rgba(102,191,255,.75); font-family: arial, sans-serif; font-size: 17px; line-height: 17px; color: #ffffff; text-align: center; text-decoration: none; padding: 13px 17px; display: block; border-radius: 4px; white-space: nowrap;">{{__ "view-my-data"}}</a>
|
<a class="s-btn s-btn__primary" href="{{selfservice_link}}" target="_parent" style="background: #0095FF; border: 1px solid #0077cc; box-shadow: inset 0 1px 0 0 rgba(102,191,255,.75); font-family: arial, sans-serif; font-size: 17px; line-height: 17px; color: #ffffff; text-align: center; text-decoration: none; padding: 13px 17px; display: block; border-radius: 4px; white-space: nowrap;">{{__ "view-my-data"}}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -331,7 +331,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding-bottom: 15px; font-family: arial, sans-serif; font-size: 15px; line-height: 21px; color: #3C3F44; text-align: left;">
|
<td style="padding-bottom: 15px; font-family: arial, sans-serif; font-size: 15px; line-height: 21px; color: #3C3F44; text-align: left;">
|
||||||
<p>Link: <a href="{{selfservice_url}}">{{selfservice_url}}</a><br>
|
<p>Link: <a href="{{selfservice_link}}">{{selfservice_link}}</a><br>
|
||||||
{{__ "if-you-ever-loose-the-link-you-can-request-a-new-one-by-visiting-our-website"}} <a href="{{forgot_link}}">{{forgot_link}}</a></p></td>
|
{{__ "if-you-ever-loose-the-link-you-can-request-a-new-one-by-visiting-our-website"}} <a href="{{forgot_link}}">{{forgot_link}}</a></p></td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- Button Row : END -->
|
<!-- Button Row : END -->
|
||||||
|
@ -7,7 +7,7 @@ The only thing you have to do now is to bring your registration code with you.
|
|||||||
You can view your registration code, lap times and much more by visiting our selfservice.
|
You can view your registration code, lap times and much more by visiting our selfservice.
|
||||||
|
|
||||||
This is your private selfservice link:
|
This is your private selfservice link:
|
||||||
{{selfservice_url}}
|
{{selfservice_link}}
|
||||||
|
|
||||||
If you ever loose the link you can request a new one by visiting our website: {{forgot_link}}
|
If you ever loose the link you can request a new one by visiting our website: {{forgot_link}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user