• Written by Rob Kleiman

What If One Email in Your Inbox Was Just Nice to You?

TL;DR

  • I built a small Google Apps Script with Claude that emails me affirmations every 3 hours.
  • The affirmation is the subject line, so I get the message without opening anything.
  • Here’s how to set up your own copy, plus one fix that keeps “random” actually random.

One email that doesn’t want anything

Most of my inbox wants something from me: a reply, a payment, a password reset. So I made one email that doesn’t.

It’s built with Google Apps Script, or GAS: JavaScript that runs on Google’s servers instead of your computer. It comes free with any Google account and has built-in access to Gmail, Calendar, Sheets and Drive. There’s nothing to install and no server to run. You write code in the browser, and Google runs it, even on a schedule.

My script picks a few affirmations from a list and sends them to me every 3 hours. No app to open, no streak to keep, no account to sign up for. I built it with Claude: I decided what it should do, and Claude wrote most of the code.

I picked email over an app or a phone notification because I already check my inbox. Nothing new to install, and nothing new to remember.

The subject line is the message

Lots of email never gets opened. You see the subject line in a list and move on. So the affirmation doesn’t hide inside the email. It is the subject. The script picks one more affirmation than the body needs and promotes the first one:

// Pick HOW_MANY + 1 — first becomes subject, rest go in the body
const all      = pickAffirmations(CONFIG.HOW_MANY + 1, CONFIG.MODE);
const headline = all[0];                   // clean headline for inside the email
const subject  = headline + " #rkaffirm"; // tagged subject for inbox/search
const picks    = all.slice(1);
const body     = buildEmailBody(picks, headline);

GmailApp.sendEmail(recipient, subject, "", { htmlBody: body, name: "Aff App" });

If you do open it, you get a clean HTML card: the headline at the top and a few more affirmations below it. The #rkaffirm tag makes these emails easy to find or filter in Gmail. Swap in your own tag.

Set up your own

You need a Google account. code.gs is about 150 lines, and about 60 of those build the email’s HTML. The full file is at the end of this section.

  1. Create a project. Go to script.google.com and click New project. New projects use the modern V8 runtime, which this code needs.
  2. Add the two files. Replace everything in the default Code.gs with the script below. Then click + → Script and name the new file list. The editor adds .gs for you.
  3. Write your list. list.gs just needs an array called AFFIRMATIONS. Apps Script shares top-level names across all files in a project, so code.gs can see it. Mine is sorted into categories. Declare each category above the AFFIRMATIONS array. Here’s the shape, with sample lines:
// list.gs (example structure, sample affirmations)
const MORNING_BOOST = [
  "Today is a good day to start something.",
  "You don't have to do it all. Just the next thing.",
];

const AFFIRMATIONS = [
  ...MORNING_BOOST,
  // ...add more categories here
];
  1. Set your email address in the config block at the top of code.gs.
  2. Send a test. Pick sendDailyAffirmations from the function menu and click Run. Google will ask you to authorize the script. Because it’s your own unverified project, you’ll see a “Google hasn’t verified this app” screen. Click Advanced, then Go to your project. Check your inbox.
  3. Start the schedule. Run createDailyTrigger() once. After that, it sends on its own.

Pro tip: re-running createDailyTrigger() won’t stack up duplicate triggers. It deletes the old one before creating a new one. (Yes, it’s called createDailyTrigger and it fires every 3 hours. Naming things is hard.)

The full code.gs
// code.gs — Main logic for the Daily Affirmations emailer

// ── CONFIG ──────────────────────────────────────────────────────────────────
const CONFIG = {
  HOW_MANY:     3,                        // Number of affirmations in the email body
  MODE:         "random",                 // "random" | "sequential"
  EVERY_HOURS:  3,                        // Send every X hours
  RECIPIENT:    "you@yourdomain.com",     // Your main inbox
};

// ── SCRIPT PROPERTY KEY (used for sequential mode) ───────────────────────────
const LAST_INDEX_KEY = "lastAffirmationIndex";

// ── ENTRY POINT ──────────────────────────────────────────────────────────────
function sendDailyAffirmations() {
  const recipient = CONFIG.RECIPIENT;

  // Pick HOW_MANY + 1 — first becomes subject, rest go in the body
  const all      = pickAffirmations(CONFIG.HOW_MANY + 1, CONFIG.MODE);
  const headline = all[0];                   // clean headline for inside the email
  const subject  = headline + " #rkaffirm"; // tagged subject for inbox/search
  const picks    = all.slice(1);
  const body     = buildEmailBody(picks, headline);

  GmailApp.sendEmail(recipient, subject, "", { htmlBody: body, name: "Aff App" });

  Logger.log(`✅ Affirmation email sent to ${recipient}`);
  Logger.log(`   Subject: ${subject}`);
  Logger.log(`   Affirmations: ${picks.join(" | ")}`);
}

// ── AFFIRMATION PICKER ────────────────────────────────────────────────────────
function pickAffirmations(count, mode) {
  if (!AFFIRMATIONS || AFFIRMATIONS.length === 0) {
    throw new Error("AFFIRMATIONS list in list.gs is empty!");
  }

  const total = AFFIRMATIONS.length;
  count       = Math.min(count, total);

  if (mode === "sequential") {
    const props    = PropertiesService.getScriptProperties();
    let   startIdx = parseInt(props.getProperty(LAST_INDEX_KEY) || "0", 10);
    const picks    = [];

    for (let i = 0; i < count; i++) {
      picks.push(AFFIRMATIONS[(startIdx + i) % total]);
    }

    props.setProperty(LAST_INDEX_KEY, String((startIdx + count) % total));
    return picks;

  } else {
    const shuffled = [...AFFIRMATIONS].sort(() => Math.random() - 0.5);
    return shuffled.slice(0, count);
  }
}

// ── EMAIL BUILDER ─────────────────────────────────────────────────────────────
function buildEmailBody(affirmations, headline) {
  const now       = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "EEEE, MMMM d · h:mm a");
  const listItems = affirmations
    .map(a => `
      <li style="
        margin-bottom: 16px;
        padding: 16px 20px;
        background: #f9f5ff;
        border-left: 4px solid #7c3aed;
        border-radius: 6px;
        font-size: 16px;
        color: #1e1b4b;
        line-height: 1.5;
      ">${a}</li>`)
    .join("");

  return `
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"></head>
<body style="margin:0;padding:0;background:#f3f4f6;font-family:'Segoe UI',Arial,sans-serif;">
  <table width="100%" cellpadding="0" cellspacing="0" style="background:#f3f4f6;padding:40px 0;">
    <tr>
      <td align="center">
        <table width="560" cellpadding="0" cellspacing="0" style="background:#ffffff;border-radius:12px;overflow:hidden;box-shadow:0 4px 20px rgba(0,0,0,0.08);">

          <!-- Header -->
          <tr>
            <td style="background:linear-gradient(135deg,#7c3aed,#4f46e5);padding:36px 40px;text-align:center;">
              <h1 style="margin:0;color:#ffffff;font-size:22px;font-weight:700;letter-spacing:-0.5px;">${headline}</h1>
              <p style="margin:8px 0 0;color:#ddd6fe;font-size:14px;">${now}</p>
            </td>
          </tr>

          <!-- Body -->
          <tr>
            <td style="padding:36px 40px;">
              <p style="margin:0 0 24px;color:#6b7280;font-size:15px;line-height:1.6;">
                Take a deep breath, read each one slowly, and carry them with you.
              </p>
              <ul style="list-style:none;margin:0;padding:0;">
                ${listItems}
              </ul>
            </td>
          </tr>

          <!-- Footer -->
          <tr>
            <td style="background:#f9fafb;padding:20px 40px;text-align:center;border-top:1px solid #e5e7eb;">
              <p style="margin:0;color:#9ca3af;font-size:12px;">
                Sent with love by Aff App &nbsp;·&nbsp; Google Apps Script
              </p>
            </td>
          </tr>

        </table>
      </td>
    </tr>
  </table>
</body>
</html>`;
}

// ── TRIGGER SETUP ─────────────────────────────────────────────────────────────
/**
 * Run createDailyTrigger() ONCE from the sender account's Apps Script editor.
 * It schedules emails every EVERY_HOURS hours automatically after that.
 */
function createDailyTrigger() {
  ScriptApp.getProjectTriggers()
    .filter(t => t.getHandlerFunction() === "sendDailyAffirmations")
    .forEach(t => ScriptApp.deleteTrigger(t));

  ScriptApp.newTrigger("sendDailyAffirmations")
    .timeBased()
    .everyHours(CONFIG.EVERY_HOURS)
    .create();

  Logger.log(`✅ Trigger created — emails will arrive every ${CONFIG.EVERY_HOURS} hours.`);
}

function deleteDailyTrigger() {
  ScriptApp.getProjectTriggers()
    .filter(t => t.getHandlerFunction() === "sendDailyAffirmations")
    .forEach(t => ScriptApp.deleteTrigger(t));

  Logger.log("🛑 Trigger removed.");
}

Make it yours

Everything you’d want to change is in one config block:

const CONFIG = {
  HOW_MANY:     3,                        // Number of affirmations in the email body
  MODE:         "random",                 // "random" | "sequential"
  EVERY_HOURS:  3,                        // Send every X hours
  RECIPIENT:    "you@yourdomain.com",     // Your main inbox
};
  • **HOW_MANY** is how many affirmations go in the body, on top of the one in the subject line.
  • **MODE** chooses "random", or "sequential", which works through your list in order and remembers its place between emails.
  • **EVERY_HOURS** sets how often the email arrives. Change it, then run createDailyTrigger() again.

To stop the emails, run deleteDailyTrigger().

One fix: make “random” actually random

Random mode shuffles with a popular one-liner, sort(() => Math.random() - 0.5). It looks fine, but it isn’t a fair shuffle. Sorting algorithms assume a comparison gives the same answer every time, and a random one tilts where items end up.

How much? I simulated the script’s picker in Node, 100,000 runs per list size. The first affirmation in the list became the subject line about 2× as often as it should with 10 affirmations, about 2.5× with 30, and about 3× with 60. The least-picked ones showed up only about 60% as often as they should.

Here’s the fix. Paste this anywhere in code.gs:

function fairShuffle(list) {
  const a = [...list];
  for (let i = a.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [a[i], a[j]] = [a[j], a[i]];
  }
  return a;
}

Then, in pickAffirmations, replace the two lines in the else branch with return fairShuffle(AFFIRMATIONS).slice(0, count);. In the same simulation, every affirmation landed within a few percent of its fair share.

Limits

  • It asks for full Gmail access. GmailApp can read and delete mail, not just send it. If that bothers you, MailApp.sendEmail(recipient, subject, "", { htmlBody: body, name: "Aff App" }) works the same way and only asks for permission to send.
  • Every 3 hours includes the middle of the night. That’s 8 emails a day, timed in your project’s time zone (in Project Settings). Raise EVERY_HOURS if that’s too many.
  • Your list goes into the HTML as-is. A stray < or & in an affirmation will be read as HTML.
  • The duplicate protection only works within one project. Two copies of the script mean two emails.

The takeaway

A small script can do one nice thing reliably. Just don’t trust a one-line shuffle to be random. Test it, or use Fisher–Yates.

Read next: Swipe Right to Keep: Turning 3,000 Contacts into a Tinder-Style App with Google Apps Script. Another small Apps Script that turned something tedious into something I actually enjoy.

Built your own version, or have an affirmation that should be on the list? Get in touch.

Keep reading

More from Things I've Built

All Things I've Built posts →