useSend icon indicating copy to clipboard operation
useSend copied to clipboard

[feat] Emails retention periods/cleanup

Open jnettome opened this issue 8 months ago • 7 comments

Hey everyone,

I'm thinking about implementing a cleanup process for old email bodies, since our database is growing significantly due to storing all message content and attachments.

Do you have any recommendations for how to approach this? Or maybe a better solution based on typical project structures?

At the moment, I'm running a SQL query via cron just to get things working in my environment, but I plan to eventually turn this into a proper feature.

Thanks again!

async function cleanupEmailBodies() {
  const result = await db.$executeRaw`
    UPDATE "Email"
    SET "text" = NULL,
        "html" = NULL
    WHERE "createdAt" < NOW() - INTERVAL '90 days'
    AND ("text" IS NOT NULL OR "html" IS NOT NULL);
  `;

  console.log(`[Cleanup] Emails cleaned: ${result}`);
}

jnettome avatar May 09 '25 14:05 jnettome

been thinking about this as well, this needs to be a cron job from the app itself.

can see a example job here: https://github.com/unsend-dev/unsend/blob/main/apps/web/src/server/jobs/usage-job.ts

if you're interested you can make a pr.

KMKoushik avatar May 09 '25 21:05 KMKoushik

@jnettome can i know how emails you're sending per day/month. just want to see how unsend holds up! thanks

KMKoushik avatar May 09 '25 21:05 KMKoushik

Not necessarily about that theme, but in the future, can be a way for download the EML file of the mail?

tpraxedes avatar May 09 '25 21:05 tpraxedes

yh, you can add it in as an issue so someone can pick it up

KMKoushik avatar May 09 '25 21:05 KMKoushik

@KMKoushik yeah, some stats:

Image

jnettome avatar May 10 '25 19:05 jnettome

@jnettome if you don't mind, is it all marketing or transactional? or at what ratio?

KMKoushik avatar May 10 '25 23:05 KMKoushik

@KMKoushik np! It's 90+% transactional - we're using unsend mainly for our ticketing platform.

jnettome avatar May 11 '25 17:05 jnettome