A sending platform records what happens to each message, but the platform does not know your business. It sees a recipient address and a subject; you know that this message was the order confirmation for order 8841, sent by the checkout service, to a customer in the premium plan. If you attach that information to the message when you send it, it comes back in logs, events and reports, and your analysis becomes far easier. Tags and metadata are the mechanism. They are small labels or key-value pairs that travel with the message through the platform and appear in webhooks and exports. This guide explains the difference between tags, categories and metadata, how to add them through an API or SMTP headers, the limits and privacy cautions, how to design a scheme that stays useful, and common patterns such as correlating webhooks with application records. See delivery event webhooks and message logs.
Tags, categories and metadata compared
| Item | Shape | Typical limit | Use for |
|---|---|---|---|
| Tag or category | One or a few short strings | A handful per message, each with a maximum length | Reporting groups: message type, stream, campaign family |
| Metadata / custom variables | Key-value pairs | A limited number of keys and total size | Linking to your records: IDs, tenant, template version |
| Custom header | Header line added to the message itself | Counted in message size | Information needed by downstream systems or recipients’ systems (note: visible to recipients) |
| Message ID | Unique identifier of the message | One per message | Primary key for lookup in logs. See Message-ID |
Check your provider's documentation for names and limits, because they differ. The important distinction is visibility: provider-side tags and metadata stay in the platform and are not shown to the recipient, while custom headers are part of the message and can be read by anyone who views the source or by the recipient's systems.
Adding labels when you send
# HTTP API (illustrative fields; names vary by provider)
POST /v1/messages
{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Your order 8841",
"tags": ["transactional", "order-confirmation"],
"metadata": {"order_id": "8841", "tenant": "acme", "template_version": "12"},
"html": "..."
}
# SMTP: provider-specific header that is removed before delivery
X-Mail-Tag: order-confirmation
X-Mail-Metadata: {"order_id":"8841","tenant":"acme"}Many platforms accept special SMTP headers that carry tags and metadata and are stripped before the message leaves the platform. Confirm that yours removes them; otherwise recipients will see internal data. Test by sending to yourself and viewing the source. See reading headers.
Using tags and metadata
- Correlate webhooks with records. When a bounce event arrives, the metadata tells you which order, user and template it belongs to, without a lookup by Message-ID. See webhooks vs polling.
- Report by message type. Compare bounce and complaint rates for onboarding, receipts, reminders and newsletters. Problems often hide in one type.
- Monitor streams separately. Tag transactional and marketing mail so that dashboards and alerts follow each stream. See separate streams.
- Debug quickly. Support can search logs by tenant or order ID instead of asking for addresses.
- Support multi-tenant platforms. A tenant tag lets you give each customer their own statistics and enforce per-tenant limits.
- Run experiments. Tag variants and template versions. See A/B testing.
- Route events. Send some events (such as security notices) to a different handler based on the tag.
Naming and design rules
- Use a small, documented vocabulary of tags, in lowercase with hyphens. Ten well-chosen tags beat two hundred ad hoc ones.
- Separate dimensions: tag the type of message, put the identifier in metadata. Do not create a tag for every order.
- Keep metadata keys stable and typed. Do not rename keys without a migration, because historical reports will split.
- Include a version for templates and for your metadata schema if it may change.
- Keep values short. They are stored with every event, and limits apply.
- Document ownership: who may add a new tag, and where the list lives.
- Avoid high-cardinality tags in dashboards (one unique value per message), which are expensive to aggregate and rarely useful.
Privacy and security
| Do | Do not |
|---|---|
| Store opaque identifiers (order_id, tenant_id, user_id) | Store passwords, tokens, one-time codes or full card numbers |
| Use internal IDs that your systems can resolve | Put personal data such as names or health details into tags |
| Check retention rules for logs and event exports. See data retention | Assume metadata is deleted when the message is |
| Keep custom headers free of internal data | Expose internal system names or customer lists to recipients through headers |
| Treat webhook payloads as sensitive, and verify signatures | Log full payloads in unprotected places |
Because metadata appears in webhooks and exports, anyone who can access those can read it. Apply the same access control as for other customer data, and include metadata in your privacy impact assessment. If a customer exercises a deletion right, you need to know where their identifiers appear.
Patterns that work
- Correlation ID. Generate an ID in your application for each email attempt, store it in your database, and send it as metadata. When an event arrives, look it up directly. Also store the provider's message ID.
- Stream and type tags. Always set stream (transactional, lifecycle, marketing) and type (receipt, reset, digest).
- Tenant tag for SaaS. Allows per-customer dashboards and abuse isolation.
- Template version. Lets you see whether a change in a template raised complaints.
- Feature or experiment flags. Link a variant to its results.
- Retry counter. Records how many attempts were needed, which helps separate your problems from provider problems. See API error handling.
Scaling the scheme
As volume and teams grow, the scheme needs care. Publish the vocabulary in a shared document and give it an owner who reviews proposals for new tags. Provide a small helper library in your codebase that builds the tags and metadata for each message type, so that individual developers do not invent their own keys. Add automated tests that fail when a template is sent without the required stream and type labels. Review the most frequent tags every quarter and retire those nobody uses. These habits keep the data clean enough for dashboards, alerts and audits to rely on, and make it far cheaper to answer a new question a year from now.
Example: debugging with tags
A support agent reports that a customer did not receive a receipt. With metadata, the agent searches the logs for the order ID and finds one message tagged order-confirmation with a bounce event: the mailbox was full. Without it, the agent would ask the customer for an address, search by address, and compare times by eye. The same labels let an engineer see that the bounce rate for receipts is low while the rate for reminders is high, pointing at a list problem in the reminder flow and not at the provider. Small labels, applied consistently, turn scattered events into a story.
Testing
- Send a message with tags and metadata to a test mailbox and verify they are absent from the visible headers and body.
- Check that the same values appear in the event payload and log search.
- Test limits: too many tags, long values and special characters, to see how the platform rejects or truncates them.
- Add a monitor for events that arrive without expected metadata, which signals a code path that forgot to set it.
A few minutes of labelling at send time saves hours of detective work later. Design the vocabulary once, keep it small and treat metadata as customer data, and your events will answer the questions you actually ask.
Get events you can correlate Tags, metadata and detailed logs for every message.
References and further reading
Frequently asked questions
What is the difference between a tag and metadata?
A tag is a short label for grouping, while metadata is key-value data such as an order ID that links the message to your records.
Are tags visible to recipients?
Provider-side tags and metadata are not, but custom headers added to the message can be seen in the source.
Can I put personal data in metadata?
Avoid it. Use opaque identifiers and treat metadata like other customer data in events and exports.
How many tags should I use?
A small documented set per message, typically type and stream, with identifiers in metadata.
How do I correlate a bounce webhook with my record?
Send your own ID as metadata and read it back in the event, and store the provider message ID as well.