Send registration email, add mail validation page, stabilize mail generation

This commit is contained in:
2024-11-26 15:22:57 +01:00
parent 4df9297d47
commit 4125cbb3a2
15 changed files with 147 additions and 53 deletions

View File

@@ -1,6 +1,9 @@
import nodemailer from 'nodemailer';
import { createSSRApp, h } from 'vue';
import { renderToString } from 'vue/server-renderer';
import postcss from 'postcss';
import tailwindcss from 'tailwindcss';
import { join } from 'node:path';
import base from '../components/mail/base.vue';
import registration from '../components/mail/registration.vue';
@@ -15,7 +18,7 @@ export const templates: Record<string, { component: any, subject: string }> = {
};
import 'nitropack/types';
import type Registration from '../components/mail/registration.vue';
import type Mail from 'nodemailer/lib/mailer';
declare module 'nitropack/types'
{
interface TaskPayload
@@ -65,22 +68,22 @@ export default defineTask({
throw new Error(`Modèle de mail ${payload.template} inconnu`);
}
const mail = {
console.time('Generating HTML');
const mail: Mail.Options = {
from: 'd[any] - Ne pas répondre <no-reply@peaceultime.com>',
to: payload.to,
html: await render(template.component, payload.data),
subject: template.subject,
attachments: [{
filename: 'logo.svg',
path: '../../public/logo.dark.svg',
cid: 'logo.obsidian.peaceultime.com',
}]
};
console.timeEnd('Generating HTML');
if(mail.html === '')
return { result: false, error: new Error("Invalid content") };
console.time('Sending Mail');
const status = await transport.sendMail(mail);
console.timeEnd('Sending Mail');
if(status.rejected.length > 0)
{
@@ -100,9 +103,11 @@ async function render(component: any, data: Record<string, any>): Promise<string
{
const app = createSSRApp({
render(){
return h(base, null, { default: () => h(component, data, []) });
return h(base, null, { default: () => h(component, data, { default: () => null }) });
}
});
return await renderToString(app);
const html = await renderToString(app);
return (`<html><body><div>${html}</div></body></html>`);
}