feat: add ical

This commit is contained in:
Philipp Dormann 2025-03-18 23:57:01 +01:00
parent 658b8d4dd8
commit 2f25937a94
Signed by: philipp
GPG Key ID: 3BB9ADD52DCA4314
3 changed files with 15 additions and 2 deletions

View File

@ -2,11 +2,13 @@ import { createTransport } from "nodemailer";
import { Queue, Worker, QueueEvents } from "bullmq";
import { config } from "../config/env";
import Redis from "ioredis";
import { Attachment } from "nodemailer/lib/mailer";
interface EmailJob {
to: string;
subject: string;
html: string;
attachments: Attachment[];
text: string;
}
@ -40,12 +42,13 @@ const worker = new Worker<EmailJob>(
QUEUE_NAME,
async (job) => {
await transporter.sendMail({
from: config.email.from,
from: { address: config.email.from, name: "Lauf für Kaya!" },
replyTo: config.email.replyTo,
to: job.data.to,
subject: job.data.subject,
text: job.data.text,
html: job.data.html,
attachments: job.data.attachments,
});
},
{

View File

@ -5,6 +5,7 @@ import { z } from 'zod'
import { EmailService } from '../services/email'
import { getEmailTemplate } from '../templates'
import { Language } from '../types'
import { Attachment } from 'nodemailer/lib/mailer'
const emailRouter = new Hono()
const emailService = new EmailService()
@ -22,7 +23,7 @@ async function generateBarcodeDataURL(data) {
emailRouter.post('/', bearerAuth({ token: process.env.AUTHKEY }), zValidator('json', sendEmailSchema), async (c) => {
let { to, templateName, language, data } = c.req.valid('json')
const attachments: Attachment[] = []
try {
const template = getEmailTemplate(templateName, language as Language)
if (templateName === "welcome") {
@ -32,6 +33,12 @@ emailRouter.post('/', bearerAuth({ token: process.env.AUTHKEY }), zValidator('js
} else {
return c.json({ success: false, error: "required params 'data.name', 'data.link', 'data.barcode_content' not provided" }, 406)
}
const attachment: Attachment = {
filename: 'invite.ics',
content: `BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//ICS Generator//NONSGML ICS Generator//DE\nBEGIN:VEVENT\nUID:1742337822408-5ghrzyi@icsgenerator.local\nDTSTAMP:20250318T224342Z\nSUMMARY:Lauf für Kaya! 2025\nDTSTART:20250523T110000Z\nDTEND:20250523T160000Z\nDESCRIPTION:Der Lauf für Kaya! 2025 findet am 23.05.2025 auf dem Sportplatz des Gymnasium Herzogenaurach statt. Zur Anmeldung einfach zum Infozelt kommen.\nLOCATION:Sportplatz Gymnasium Herzogenaurach\nBEGIN:VALARM\nACTION:DISPLAY\nDESCRIPTION:Erinnerung: Lauf für Kaya! 2025\nTRIGGER:-PT1440M\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR`,
contentType: 'text/calendar; method=REQUEST',
}
attachments.push(attachment)
}
if (templateName === "password-reset") {
if (data.token) {
@ -45,6 +52,7 @@ emailRouter.post('/', bearerAuth({ token: process.env.AUTHKEY }), zValidator('js
data.event_name = process.env.EVENT_NAME
await emailService.sendEmail({
to,
attachments,
subject: template.subject(data),
html: template.html(data),
text: template.text(data)

View File

@ -1,10 +1,12 @@
import { emailQueue } from '../queues/email.queue'
import { config } from '../config/env'
import { Attachment } from 'nodemailer/lib/mailer'
interface EmailOptions {
to: string
subject: string
html: string
attachments: Attachment[]
text: string
}