From df9313b3b49f4cefebca332b5744210350ae4070 Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Tue, 19 Aug 2025 15:37:21 +0200 Subject: [PATCH] Add logo attachment to email and update image source in Base component --- apps/infoalloggi/emails/base.tsx | 10 ++++++---- .../src/server/api/routers/test.ts | 19 ++++++++++++++++++- .../infoalloggi/src/server/services/mailer.ts | 13 +++++++++++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/apps/infoalloggi/emails/base.tsx b/apps/infoalloggi/emails/base.tsx index 9f06ec7..d88a950 100644 --- a/apps/infoalloggi/emails/base.tsx +++ b/apps/infoalloggi/emails/base.tsx @@ -45,10 +45,12 @@ const Base = ({ referrerPolicy="no-referrer" width={230.5} height={44.25} - src={ - "https://lh3.google.com/u/0/d/1nEurjVWPiz0F8QRLhKcT4ZSujeFRChBs" //TEMP FIX - //getMediaUrl("/Infoalloggi.png") - } + // src={ + // process.env.NEXT_PUBLIC_BASE_URL?.includes("localhost") + // ? "https://lh3.google.com/u/0/d/1nEurjVWPiz0F8QRLhKcT4ZSujeFRChBs" + // : process.env.NEXT_PUBLIC_BASE_URL + "/Infoalloggi.png" + // } + src="cid:logo" alt="Infoalloggi.it" className="mx-auto my-2 scale-80" /> diff --git a/apps/infoalloggi/src/server/api/routers/test.ts b/apps/infoalloggi/src/server/api/routers/test.ts index ea096b1..d1bac42 100644 --- a/apps/infoalloggi/src/server/api/routers/test.ts +++ b/apps/infoalloggi/src/server/api/routers/test.ts @@ -1,9 +1,26 @@ -import { createTRPCRouter, protectedApiProcedure } from "~/server/api/trpc"; +import { + createTRPCRouter, + protectedApiProcedure, + publicProcedure, +} from "~/server/api/trpc"; +import { genMail, NewMail } from "~/server/services/mailer"; export const testRouter = createTRPCRouter({ testApi: protectedApiProcedure.query(async () => { return "Hello World!"; }), + testMail: publicProcedure.query(async ({ ctx }) => { + const mail = await NewMail({ + to: "m.pedone98@gmail.com", + subject: "Test Email", + + mailType: "pwResetLink", + props: { + resetlink: "https://example.com/reset-password", + }, + }); + return mail; + }), /* PROTECTED API CALL EXAMPLE diff --git a/apps/infoalloggi/src/server/services/mailer.ts b/apps/infoalloggi/src/server/services/mailer.ts index 3897b76..c29aa29 100644 --- a/apps/infoalloggi/src/server/services/mailer.ts +++ b/apps/infoalloggi/src/server/services/mailer.ts @@ -18,7 +18,7 @@ import type { Recesso_NewMail } from "emails/recesso"; import Recesso from "emails/recesso"; import type { RegistrazioneAvvenuta_NewMail } from "emails/registrazione-avvenuta"; import RegistrazioneAvvenuta from "emails/registrazione-avvenuta"; -import { createTransport } from "nodemailer"; +import { createTransport, type TransportOptions } from "nodemailer"; import { htmlToText } from "nodemailer-html-to-text"; import { env } from "~/env.mjs"; import type { JSX } from "react"; @@ -36,6 +36,7 @@ import type { Generic_NewMail } from "emails/gereric-email"; import Generic from "emails/gereric-email"; import { GetFlagValueHandler } from "~/server/controllers/flags.controller"; import { db } from "~/server/db"; +import type { Options } from "nodemailer/lib/mailer"; type MailerProps = { to: string; @@ -60,11 +61,19 @@ const mailer = async ({ to, subject, html }: MailerProps) => { }); smtpTransport.use("compile", htmlToText()); - const message = { + const message: Options = { from: `"InfoAlloggi" <${env.ARUBA_USER}>`, to: to, subject: subject, html: html, + attachments: [ + { + filename: "Infoalloggi.png", + path: "./public/Infoalloggi.png", + contentType: "image/png", + cid: "logo", + }, + ], }; smtpTransport.sendMail(message, (err, info) => { if (err) {