M
MelMeDocs
Sending Emails

Email Templates & Media

Create reusable email templates with AWS S3-backed attachments and dispatch them programmatically using developer API keys.

1. Overview

MelMe Email Templates allow you to define standardized outbound messages with pre-configured subjects, sender identities, rich HTML/plain text layouts, default recipients, and media attachments.

Templates are designed specifically for programmatic dispatch via Developer API Keys. Instead of sending large HTML payloads and repetitive attachments with each API call, you simply pass a templateId to /api/v1/emails/send.


2. Managing Templates in Dashboard

Navigate to the Templates section in the MelMe sidebar:

  1. Click Create Template.
  2. Set a Template Name (e.g. Welcome Onboarding, Monthly Invoice).
  3. Enter a Subject Line (supports dynamic variable placeholders like Welcome {{name}}!).
  4. (Optional) Select a default From Address from your verified domains, or set default To, CC, or BCC addresses.
  5. Provide HTML Content and Plain Text Fallback. Use the Live Preview tab to test visual rendering.
  6. Upload any Media & Attachments (PDFs, images, documents up to 10MB per file).
  7. Save the template and copy its Template ID (cuid).

3. AWS S3 Storage Architecture

Attachments uploaded for email templates are isolated and structured securely in your AWS S3 bucket:

s3://<AWS_BUCKET_NAME>/
└── templates/
    └── <userId>/
        └── <templateId>/
            ├── 1740000000000-a1b2c3d4-terms_of_service.pdf
            └── 1740000000000-e5f6g7h8-welcome_brochure.png

Key Principles of S3 Template Media Management:

  1. User & Template Isolation: Files are scoped strictly under templates/{userId}/{templateId}/. No two users or templates share the same folder.
  2. Deterministic Cleanup on Deletion: When a template is deleted from MelMe, the system automatically purges every stored attachment file from AWS S3 in addition to removing database records.
  3. Dynamic Replacement & Removal: If you delete or replace an attachment from an existing template, the previous object is immediately deleted from S3 via DeleteObjectCommand.
  4. Security & Validation: Attachments are sanitized, checked against a 10MB per file limit, and assigned unique random prefixes to avoid filename collisions.

4. Sending Templated Emails via API Key

Templates are dispatched by calling POST /api/v1/emails/send with an API Key and templateId.

Basic Dispatch with Dynamic Recipient

curl -X POST https://api.melme.aryanshinde.in/v1/emails/send \
  -H "Authorization: Bearer mm_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "cuid_template_id_here",
    "to": "client@example.com",
    "variables": {
      "name": "Jane Doe",
      "company": "Acme Corp"
    }
  }'

How Fields Are Resolved:

FieldSource Priority
toRequest body to > Template to
fromRequest body from > Template fromEmail
senderNameRequest body senderName > Template senderName
subjectRequest body subject > Template subject (with variable replacement)
htmlRequest body html > Template bodyHtml (with variable replacement)
textRequest body text > Template bodyText (with variable replacement)
attachmentsCombined: All template S3 attachments + any extra attachments passed in request body

5. Dynamic Variable Substitution

You can place {{variable_name}} tags anywhere within your template's Subject, HTML, or Plain Text body.

When calling the API, supply a variables dictionary:

{
  "templateId": "cuid_template_id_here",
  "to": "alice@example.com",
  "variables": {
    "name": "Alice Smith",
    "plan": "Enterprise Tier",
    "renewal_date": "March 31, 2026",
    "dashboard_url": "https://melme.aryanshinde.in/domains"
  }
}

The template engine will automatically replace every matching {{name}}, {{plan}}, {{renewal_date}}, etc., with the escaped dynamic value.


6. Overrides & Extra Attachments

You can attach additional files dynamically at runtime without modifying the static template. Any runtime attachments are appended alongside the template's S3 media:

curl -X POST https://api.melme.aryanshinde.in/v1/emails/send \
  -H "Authorization: Bearer mm_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "cuid_template_id_here",
    "to": "client@example.com",
    "subject": "Custom Quarterly Statement for {{name}}",
    "variables": {
      "name": "Bob"
    },
    "attachments": [
      {
        "filename": "custom-statement-march.pdf",
        "url": "https://storage.mycompany.com/invoices/march-bob.pdf"
      }
    ]
  }'

On this page