ses-lambda-mailer
README.md

Serverless Scheduled Email Notifier

AWS Lambda · Amazon SES · Amazon EventBridge Scheduler

A hands-on project exploring Amazon SES as a verified sending domain with multiple sender identities, wired up to three independent, schedule-triggered AWS Lambda functions.

AWS Lambda Amazon SES Amazon EventBridge IAM CloudWatch Logs Python (boto3) Serverless

Overview

This project was built to understand how Amazon SES works as a verified sending domain with multiple named identities. The domain sharathonline.com is verified once in SES, and three distinct "personas" send from it: happy-morning@sharathonline.com, happy-evening@sharathonline.com, and story-time@sharathonline.com. Three independent AWS Lambda functions generate content and send email through SES, each triggered on its own weekday schedule via Amazon EventBridge — with no servers to manage.

Architecture Diagram

flowchart TB
    subgraph SCH["Amazon EventBridge Scheduler"]
        S1["⏰ Weekdays @ 10:00 AM IST"]
        S2["⏰ Weekdays @ 6:30 PM IST"]
    end

    subgraph LAM["AWS Lambda"]
        L1["λ morning-mailer.py<br/>random quote from quotes.txt"]
        L2["λ story-mailer.py<br/>fetches story + moral via HTTPS"]
        L3["λ evening-mailer.py<br/>random quote from quotes.txt"]
    end

    API["🌐 External API<br/>shortstories-api.onrender.com"]

    subgraph SES["Amazon SES — Verified Domain: sharathonline.com"]
        I1["✉ happy-morning@sharathonline.com"]
        I2["✉ story-time@sharathonline.com"]
        I3["✉ happy-evening@sharathonline.com"]
    end

    REC["📥 Recipient Inbox(es)<br/>via RECIPIENT_EMAIL env var"]
    CW["📊 Amazon CloudWatch Logs<br/>execution logs & errors"]

    S1 --> L1
    S1 --> L2
    S2 --> L3

    L2 <-->|HTTPS GET| API

    L1 --> I1
    L2 --> I2
    L3 --> I3

    I1 --> REC
    I2 --> REC
    I3 --> REC

    L1 -.-> CW
    L2 -.-> CW
    L3 -.-> CW

Fig. 1 — Scheduled, event-driven email pipeline across three independent Lambda functions sharing one verified SES domain

Lambda Functions

Function Sender Identity Content Source Schedule (EventBridge) Notes
morning-mailer.py happy-morning@sharathonline.com quotes.txt (random pick) Weekdays, 10:00 AM IST Supports multiple recipients (comma/semicolon separated) from one env var
evening-mailer.py happy-evening@sharathonline.com Accomplishment-themed quotes file Weekdays, 6:30 PM IST Same random-quote pattern, different tone/content set
story-mailer.py story-time@sharathonline.com External API: shortstories-api.onrender.com Weekdays, 10:00 AM IST Subject line built dynamically from the story's moral; handles HTTPError/URLError

How It Works

  • Amazon EventBridge Scheduler rules trigger each Lambda on a cron schedule — no polling, no always-on compute.
  • morning-mailer and evening-mailer read a bundled quotes file, pick one at random with random.choice(), and email it as plain text.
  • story-mailer calls the public Story API over HTTPS, extracts the story and its moral, and uses the moral as the email subject.
  • All three functions read the recipient list from a RECIPIENT_EMAIL Lambda environment variable and support multiple comma/semicolon-separated addresses.
  • Each function sends via boto3's SES send_email API using its own verified sender identity under the shared domain.
  • Execution logs and errors are captured automatically in Amazon CloudWatch Logs for observability.

Key Learnings

  • How a single verified SES domain can back multiple sender addresses/identities without re-verifying each one.
  • Designing small, single-purpose Lambda functions decoupled from their trigger schedule via EventBridge.
  • Handling external API failures gracefully (HTTPError vs. URLError) in a serverless function.
  • Passing configuration (recipients) through environment variables instead of hardcoding.

Sample Email Outputs

morning-mailer.py evening-mailer.py story-mailer.py
morning-mailer sample email evening-mailer sample email story-mailer sample email
happy-morning@sharathonline.com happy-evening@sharathonline.com story-time@sharathonline.com

Fig. 2 — Actual delivered emails from each scheduled Lambda function