Recipient variables allow you to inject recipient-specific data into any part of your email — subject line, greeting, body, links, and images — creating a uniquely personalised experience for each person on your list. This article covers how to define, structure, and use variables effectively across all template and send scenarios.
Variable Data Types
Variables in MigoSMTP are always rendered as strings in the email, but the data you pass can represent different types:
| Data Type | Example Variable | Example Value | Rendered In Email |
|---|---|---|---|
| Text / String | {{first_name}} | "Rahul" | Rahul |
| Number | {{order_total}} | "2,499.00" | 2,499.00 |
| Currency | {{currency}}{{amount}} | "₹" + "1,499" | ₹1,499 |
| Date / Time | {{delivery_date}} | "15 June 2026" | 15 June 2026 |
| URL | {{tracking_url}} | "https://track.co/xyz" | https://track.co/xyz (as href) |
| HTML snippet | {{product_list_html}} | "<li>Item 1</li>" | Rendered as HTML (use with care) |
| Boolean flag | {{is_premium}} | "true" or "false" | Used with conditional blocks — not rendered directly |
Variable Naming Conventions
A consistent naming convention across all your templates and send requests makes maintenance far simpler. Recommended convention:
| Category | Recommended Names |
|---|---|
| Recipient personal data | first_name, last_name, full_name, email, phone |
| Order / transaction | order_id, order_total, order_date, currency, payment_method |
| Product | product_name, product_sku, product_image_url, product_price |
| Account / subscription | account_id, plan_name, trial_end_date, next_billing_date |
| Action URLs | cta_url, tracking_url, unsubscribe_url, reset_url, verify_url |
| Flags / booleans | is_premium, has_discount, show_upsell, is_first_order |
Practical Personalisation Examples
Order Confirmation Email
<h2 style="...">Hi {{first_name}}, your order is confirmed! 🎉</h2>
<p>Order number: <strong>#{{order_id}}</strong></p>
<p>Total paid: <strong>{{currency}}{{order_total}}</strong></p>
<p>Expected delivery: {{delivery_date}}</p>
<a href="{{tracking_url}}">Track Your Order →</a>
SaaS Trial Expiry Reminder
<h2>{{first_name}}, your {{plan_name}} trial expires in {{days_remaining}} days</h2>
<p>You've sent {{emails_sent}} emails during your trial.
Upgrade now to keep sending without interruption.</p>
<a href="{{upgrade_url}}">Upgrade to {{recommended_plan}}</a>
Newsletter with Personalised Section
<p>Hi {{first_name}},</p>
<p>Based on your interest in {{topic_category}}, here's what we picked for you this week:</p>
<!-- Article 1 -->
<h3><a href="{{article_1_url}}">{{article_1_title}}</a></h3>
<p>{{article_1_summary}}</p>
Passing Variables via the API
Single Recipient
POST /v1/email/send
{
"from": "orders@yourcompany.com",
"to": "rahul@example.com",
"template_id": "order-confirmation-v2",
"variables": {
"first_name": "Rahul",
"order_id": "ORD-98765",
"order_total": "2,499.00",
"currency": "₹",
"delivery_date": "15 June 2026",
"tracking_url": "https://yourcompany.com/track/ORD-98765"
}
}
Bulk Send — Per-Recipient Variables
POST /v1/email/send/bulk
{
"from": "orders@yourcompany.com",
"template_id": "order-confirmation-v2",
"recipients": [
{
"to": "rahul@example.com",
"variables": { "first_name": "Rahul", "order_id": "ORD-001", "order_total": "2,499" }
},
{
"to": "priya@example.com",
"variables": { "first_name": "Priya", "order_id": "ORD-002", "order_total": "3,199" }
},
{
"to": "arjun@example.com",
"variables": { "first_name": "Arjun", "order_id": "ORD-003", "order_total": "899" }
}
]
}
Common Personalisation Mistakes
| Mistake | Result | Prevention |
|---|---|---|
| Not providing a variable that exists in the template | Recipient sees literal {{first_name}} in the email — looks broken and unprofessional |
Always set fallback values; validate variable completeness before each send |
| Case mismatch in variable name | Template uses {{first_name}} but code sends firstName — tag not replaced |
Standardise all variable names to lowercase_underscore across templates and API calls |
| HTML in a text variable without HTML encoding | A user's name that contains < or & could break the email HTML |
Sanitise variable values before passing to API; never trust raw user input |
| Overly long variable value | A very long value breaks the email layout (e.g. long product name wraps in unexpected places) | Truncate variable values on your side before passing to the API |