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:
- Click Create Template.
- Set a Template Name (e.g.
Welcome Onboarding,Monthly Invoice). - Enter a Subject Line (supports dynamic variable placeholders like
Welcome {{name}}!). - (Optional) Select a default From Address from your verified domains, or set default To, CC, or BCC addresses.
- Provide HTML Content and Plain Text Fallback. Use the Live Preview tab to test visual rendering.
- Upload any Media & Attachments (PDFs, images, documents up to 10MB per file).
- 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.pngKey Principles of S3 Template Media Management:
- User & Template Isolation: Files are scoped strictly under
templates/{userId}/{templateId}/. No two users or templates share the same folder. - 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.
- Dynamic Replacement & Removal: If you delete or replace an attachment from an existing template, the previous object is immediately deleted from S3 via
DeleteObjectCommand. - 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:
| Field | Source Priority |
|---|---|
to | Request body to > Template to |
from | Request body from > Template fromEmail |
senderName | Request body senderName > Template senderName |
subject | Request body subject > Template subject (with variable replacement) |
html | Request body html > Template bodyHtml (with variable replacement) |
text | Request body text > Template bodyText (with variable replacement) |
attachments | Combined: 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"
}
]
}'