Deadline reminders from your own database: how to build a service that emails a templated attachment N days before renewal and never lets you forget

You know the feeling: a license renews on Friday, you find out on Thursday evening, and the person who has to sign is on a plane. The reminder was somewhere — a note, a calendar event, a Slack message to yourself — and it did not fire when it mattered. This guide walks through building a small service over your own database that checks deadlines every morning, sends a templated email with the renewal document attached N days before the date, and escalates if nobody confirms. By the end you will have a working build with clear owners for each step, a way to prove a reminder actually went out and was opened, and an honest picture of the time and money it takes.

What do I actually get at the end?

The result is small and boring on purpose. A table with your deadlines, a scheduled job that runs once a day, and a mailbox that sends real emails. Here is what you see when it works:

  • Every morning a scheduled run queries the table, finds rows whose renewal date is exactly N days away, and sends one email per row with a PDF or DOCX built from a template.
  • The email lands in the inbox of the person who owns the renewal, in their timezone, with the contract name in the subject line.
  • A log row is written with the send time, the message ID, and the template version — so you can answer "did it go out?" without guessing.
  • If nobody confirms renewal within X days, a second email goes to a manager or a shared inbox, and the escalation is visible in the log.

That is the whole product. No dashboards unless you want them later, no fancy UI. A CSV export and a text log cover most of what you need in the first months.

A quick example to ground the numbers. Suppose you track 40 contracts and subscriptions, average renewal cycle 12 months, and you want a reminder 30 days before. That is roughly 40 emails per year for the main reminder, plus maybe 10 escalations for the ones that slip. Nothing that needs a queue, a worker fleet, or a message broker. A single cron job and a database table will do.

What does the table look like, and who decides the fields?

This is the first place where AI earns its keep, and the first place where a human has to be careful.

What the AI does: you describe your contracts in plain language ("some are software licenses with annual renewal, some are service contracts with a notice period of 60 days, some are subscriptions billed monthly") and ask for a schema. It will usually suggest something close to this:

Column Type Purpose
id UUID or integer primary key
title text contract or subscription name
counterparty text vendor or client
renewal_date date the date the renewal happens
notice_days integer how many days before renewal to remind
owner_email text who gets the reminder
escalate_to text who gets the escalation
escalate_after_days integer how long to wait for confirmation
status text active, confirmed, cancelled, done
last_reminded_at timestamp guard against double sends
document_template text which template to render

What the human decides:

  • Timezone and date semantics. Is renewal_date a calendar date in a specific timezone, or a moment in time? If your team is in Berlin and the vendor is in San Francisco, "renewal on the 1st" means different things. Store dates as plain dates and choose one reference timezone for the check — usually your operations timezone. Do not store a timestamp unless the contract genuinely has a time-of-day deadline.
  • Notice period vs reminder date. These are two different numbers. The notice period is what the contract requires you to give the vendor (often 30 or 60 days). The reminder lead time is when you want to be pinged (often earlier than the notice period). Put both in the table if the distinction matters; otherwise the reminder will arrive after the legal deadline.
  • Owner, not "team". A shared inbox as owner is how reminders get lost. Put a named person in owner_email and a shared address only in escalate_to.

A common mistake at this step: importing a renewal date as a free-text string because the source spreadsheet had "Q1 2027" or "end of March" in it. The daily check will silently skip those rows. Decide at import time how fuzzy dates become real dates — either a concrete day with a note, or a separate status that the check treats as "needs a human".

How do I build the daily check so it does not fire twice or miss days?

The check is the heart of the service. AI writes it quickly; the human owns the edge cases.

What the AI does: you ask for a script that, given a date, selects rows where renewal_date - notice_days = today and status = 'active', sends the email, and updates last_reminded_at. A reasonable first version in SQL looks like this:

SELECT id, title, owner_email, document_template
FROM renewals
WHERE status = 'active'
  AND renewal_date - notice_days = CURRENT_DATE
  AND (last_reminded_at IS NULL OR last_reminded_at::date < CURRENT_DATE);

The second condition is the guard against double sends: if the job runs twice in a day, or you rerun it manually after a fix, the row is skipped the second time. This is not optional. Cron jobs get restarted, deploys happen mid-run, and someone will click "run now" to test.

What the human checks:

  • What happens if the job does not run on a given day? If the server was down or the scheduler skipped a day, an exact-match query (= today) will miss the reminder forever. Two options: run a catch-up query that looks for rows where renewal_date - notice_days <= today and no reminder has been sent yet, or accept the risk and monitor the job. For deadlines that cost money when missed, take the catch-up option.
  • Timezones. CURRENT_DATE in PostgreSQL uses the server's timezone setting. If the server is in UTC and your team is in UTC+3, a job that runs at 09:00 local is 06:00 UTC — fine, but a job that runs at 00:30 local is 21:30 UTC the previous day, and CURRENT_DATE will be yesterday. Either run the job well inside the working day, or set the timezone explicitly in the query.
  • Duplicates from the source. If the same contract was entered twice (different capitalization, missing space), you get two reminders and two people confused. Add a uniqueness check on (title, counterparty, renewal_date) or run a deduplication query before the first live send.
Run the check in dry-run mode first Add a `--dry-run` flag that prints which rows would be selected and which emails would be sent, without sending. Run it for two weeks against real data before turning on live sends. You will find timezone bugs, fuzzy dates, and duplicates this way for free.

How do I turn a contract into an attachment without hand-editing every file?

This is where most homegrown reminder systems quietly die: the email goes out, but the attachment is a stale PDF from last year.

What the AI does: you give it a sample of the document — a renewal notice, an internal approval form, whatever the recipient actually needs — and ask for a template plus the code that fills it. If the source is a DOCX, a library like docxtpl (Python) or docx-templates (Node.js) lets you put {{ contract_title }} placeholders directly into the Word file and render them. If the source is HTML and the output should be PDF, a headless browser or a library like WeasyPrint does the job. Ask for a template that includes the renewal date, the counterparty, the notice period, and a line for the owner to sign or confirm.

What the human checks:

  • The rendered file opens. Rendering libraries fail quietly on missing fields. Add a check that the output file exists, is non-zero bytes, and opens in a viewer. A five-line test that renders the template with dummy data and checks the page count is enough.
  • The template version is logged. Store a template_version alongside each send. When someone edits the template in six months and the legal wording changes, you need to know which version went out with which contract.
  • Personal data in the attachment. If the document contains salary, bank details, or ID numbers, the email is now a data transfer. Check what your data protection obligations require for sending that document to that recipient — under the GDPR where it applies, and under the data protection act of the jurisdiction you operate in. A reminder email with a contract summary is usually fine; a reminder email with a signed NDA attached to a shared inbox deserves a second look.

Which accesses do I need, and where can this get stuck?

You cannot build this without three things: database access, a mailbox that can send, and a scheduler. Each has a real path to obtain and a real point of failure.

Database. You need a connection string with read and write access to the renewals table (write, because the script updates last_reminded_at). If the database is managed (a cloud Postgres, MySQL, or a hosted service), the admin can create a user for the service. If the database is behind a corporate firewall with no outbound access, the scheduler has to run inside the same network — this is the most common blocker and it is a decision, not a technical problem. Ask early.

Mailbox. Two options:

  • SMTP with an app password or service account. Works with most providers, but many consumer mail providers limit daily sends and require app-specific passwords. Check the provider's documentation for the exact limits and the required authentication. Gmail, for example, requires an app password if 2-step verification is on, and free accounts have lower sending limits than workspace accounts.
  • A transactional email API (SendGrid, Postmark, Mailgun, Amazon SES, and similar). Better deliverability, proper bounce handling, and a message ID you can use for tracking. Requires an API key and, for some providers, domain verification (SPF and DKIM records). This is a human task — DNS records need someone with access to the domain.

Scheduler. A cron entry on a server, a systemd timer, a cloud scheduler (AWS EventBridge, Google Cloud Scheduler, GitHub Actions cron), or a platform like Render or Railway with built-in cron. If you are already on a cloud provider, the built-in scheduler is usually the least friction. If you have no server at all, GitHub Actions on a schedule works for small volumes but is not designed for guaranteed delivery — check the docs for the minimum interval and the reliability guarantees before relying on it for money-critical reminders.

The blocker is almost never the code The three things that stop this project are: no outbound network from the database, no rights to add DNS records for the sending domain, and no one willing to own the escalation. Solve those before writing the script.

How do I know a reminder actually went out and was opened?

"I sent it" is not proof. Here is what you can actually verify, in order of strength.

  1. The send log. Every send writes a row: contract_id, sent_at, provider_message_id, template_version, recipient. If the send fails, the row records the error. This is the minimum and it is not optional.

  2. The provider's delivery status. Transactional email APIs expose delivery events (delivered, bounced, dropped) via webhooks or a status endpoint. A bounced reminder means the address is wrong — the service should mark the row and alert the owner, not retry forever.

  3. The open event. Open tracking works by embedding a tiny image that loads when the email is opened. It is approximate: many clients block images by default, and some corporate mail gateways pre-fetch images, producing false opens. Use it as a signal, not as proof. If you need certainty, ask the recipient to click a confirm link — that is a real action, not an image load.

  4. The confirmation loop. This is the one that actually closes the problem. The email contains a link or a reply instruction: "Reply CONFIRMED" or click a link that sets status = 'confirmed'. If no confirmation arrives within escalate_after_days, the escalation email goes to escalate_to. Now the system is not just sending — it is tracking whether the human did their part.

The loop that stops deadlines from slipping: check, send, wait for confirmation, escalate
1
Daily check
Query rows where renewal_date - notice_days = today
2
Send email
Templated attachment, logged with message ID
3
Wait for confirmation
Reply or signed link sets status = confirmed
4
Escalate
No confirmation after N days → escalate_to gets a second email

A simple confirmation link can be a signed URL: a token containing the contract ID and an expiry, verified by a small endpoint. AI writes the token generation and verification in a few minutes; the human decides the expiry (long enough for a person on vacation, short enough that a stale link does not confirm a contract that already renewed).

What breaks in practice, and what do I do about it?

Three failure modes are common enough to plan for.

The job runs, but the email lands in spam. A new sending domain with no SPF, DKIM, or DMARC records looks suspicious to mailbox providers. The symptom is that the send log says "delivered" but the recipient never sees it. The fix is domain authentication — a human task with the DNS admin — plus a warm-up period if the volume is meaningful. For a few dozen emails a year, a reputable transactional provider handles most of this for you.

The reminder fires, but the deadline was already wrong. Someone changed the renewal date in the source spreadsheet and did not update the database, or updated it after the reminder went out. The fix is a small reconciliation job: compare the renewals table against the source of truth weekly and flag differences. If the spreadsheet is the source of truth, import from it on a schedule instead of editing the database by hand.

The recipient leaves the company. The owner email bounces, escalation fires to a manager who also left, and the reminder disappears into a black hole. The fix is a monthly check that all owner_email and escalate_to addresses still resolve — a simple validation query against your directory or a test send to a monitoring address. Add a rule: any bounce on a reminder marks the row for human review.

How do I test this without waiting a month for a real deadline?

The check is date logic, and date logic has edge cases that only appear at boundaries. AI is good at generating these tests; a human has to review that the expected behavior is actually what you want.

Ask for tests that cover:

  • Leap day. A contract renewing on February 29 — what happens in a non-leap year? The reminder should fire on a sensible nearby date, not crash.
  • Month boundaries. A reminder 30 days before March 1 falls in late January or early February depending on the year. Check the arithmetic.
  • Timezone edges. A job running near midnight in a timezone different from the server's.
  • Double runs. The same day's job executed twice — exactly one email should go out.
  • Missed days. The job did not run yesterday — does today's run catch up?
  • Status transitions. A contract marked cancelled after the reminder was sent — should the escalation still fire? Decide and test.

The success sign for each test is a specific expected output: which rows are selected, how many emails, which log entries. If the test only checks "no error," it is not testing anything.

What does this cost me in time and money?

Time, for a developer working with an AI agent:

  • Schema and import: half a day, mostly spent on cleaning the source data.
  • The daily check and send script: a few hours. The dry-run period is calendar time, not work time.
  • Template and attachment rendering: half a day, more if the document is complex.
  • Confirmation and escalation: half a day.
  • Testing and the first live week: a day, spread out.

Call it two to four working days for a working version, plus two weeks of dry-run observation before you trust it with real deadlines.

Money, order of magnitude:

  • Hosting: a small VM or a serverless function on a schedule costs a few dollars a month, or nothing if you already have infrastructure.
  • Transactional email: most providers have a free tier for a few hundred emails a month; beyond that, pricing scales per thousand sends. Check current rates — they change.
  • Database: if you already have one, nothing. If not, a small managed instance is in the low tens of dollars per month.

The real cost is the human time to clean the data and own the escalation. That is the part AI cannot do for you.

If the build is longer than you want to own — the database is behind a firewall, the document templates are messy, the escalation rules involve several people — asibiont.com takes such projects on turnkey: the developer names the price, you top up the balance and get the working service. Details are at https://asibiont.com/en/subscription-tiers.

The part that matters most is the confirmation

A reminder service that only sends emails is a slightly better calendar. The thing that stops deadlines from slipping is the loop: send, wait for confirmation, escalate if none arrives. Build the send first, but do not call it done until the confirmation and the escalation work — because the day a reminder goes out and nobody acts on it is the day you find out whether the service was real or just another note in the pile.

If you would rather not build it yourself: we take such a project on — you describe the task, we build it and bring it to a working result, and the developer names the price. The payment goes through a balance top-up on the payment page.

← All posts

Ask AI about this article

Ask a question about this article — ASI Biont will answer based on its text.