The bill for emailing a generated media report has several possible components: message submission, attachment storage, retained message copies, and the engineering work needed to reconstruct a disputed send. For a concrete sizing example, take a 3 MiB PDF attachment. MIME base64 encoding turns its contents into 4 MiB before line wrapping and message headers. Retain ten independently stored encoded copies and that becomes 40 MiB of attachment payload. These are calculated sizes for an example, not measured traffic or a service quote.
Short answer: choose a transactional email API by who owns the report template, which attachment representation crosses its boundary, and how long each copy survives. A claim about the cheapest service needs current terms and an actual workload; a message rate alone cannot establish it. For this media workflow, start by counting retained attachment bytes, then decide which template and delivery evidence must survive deletion.
Bytes accumulate quietly.
What should a transactional email service API retain for report attachments?
For the attachment component, the useful quantity is byte-days: stored size multiplied by retention duration, summed across copies. In the example above, one unencoded 3 MiB report retained for 30 days accounts for 90 MiB-days. Ten separately stored encoded copies held for the same period account for 1,200 MiB-days before wrapping overhead. That makes copy count the larger storage multiplier in this particular example. It does not establish that storage dominates the total invoice: a service might bundle storage, charge for other usage, or deduplicate objects. Confirm its accounting boundary before translating any byte count into money.
This distinction changes the selection conversation. Ask where the generated PDF lives, whether a send creates another retained body, and whether debugging or replay captures the attachment again. Include backups and failed-job records in that inventory. A reference to an object is different from another serialized copy of its bytes. An attachment size limit is also relevant even when storage carries no separate charge, because encoded size and raw file size differ.
The change that moves our example's storage term is straightforward: retain one report artifact for the permitted period and keep references in job records. Avoid persisting a second full MIME message merely to prove that a submission happened. If audit requirements demand an exact message archive, budget that copy explicitly instead of assuming a template revision can reconstruct it.
Template ownership defines what can be reconstructed
For a media report, separate the report generator from the email wrapper. The generator owns the attachment's content and layout. The wrapper owns the subject, explanatory text, recipient-facing context, and attachment filename. A hosted email template cannot reproduce a PDF unless the report generator and its inputs are also reproducible. That is the first custody boundary to document.
Application-owned wrappers make the template revision part of the application release. They also make the application team responsible for rendering and testing the message. Externally hosted wrappers can let editors change copy through a separate workflow, but evaluation must establish how a send identifies the revision that actually rendered. Do not infer immutable versions, export support, or historical rendering from the presence of a template editor. Require evidence for each capability that matters.
For this design, keep wrapper source under revision control and generate the attachment separately. The reason is reconstruction: a report dispute should identify a report artifact and a wrapper revision without requiring a retained copy of every rendered email. This choice costs editorial autonomy. Copy changes follow the release process unless the team builds a reviewed publishing path for them.
A useful job record contains an internal report identifier, wrapper revision, attachment digest, retention deadline, and delivery correlation identifier. Keep the recipient address in a separately controlled record if the workflow allows it. A digest can check a candidate artifact against the recorded value; it cannot recover deleted bytes or prove that a recipient read the report. Template variables can contain sensitive information too. Treat their retention as a deliberate decision rather than logging the entire render context by default.
Build the message once, then measure its actual boundary
The following Python example builds a small media-report email with a PDF attachment. It illustrates application-owned rendering and local size inspection. It does not submit a message or invent a universal HTTP contract: attachment fields, authentication, request size limits, and retry behavior belong to the selected API's documented contract. Some interfaces accept raw message bytes; others accept a structured message with an encoded attachment. Measure the representation that the interface actually receives.
from email.message import EmailMessage
from email.policy import SMTP
from hashlib import sha256
from pathlib import Path
def build_report_message(report_path: Path, recipient: str):
report_bytes = report_path.read_bytes()
digest = sha256(report_bytes).hexdigest()
message = EmailMessage(policy=SMTP)
message["From"] = "Audience Desk <reports@example.org>"
message["To"] = recipient
message["Subject"] = "Your audience report is attached"
message.set_content(
"The requested audience report is attached as a PDF.\n"
"Reply to the audience desk with questions about its contents.\n"
)
message.add_attachment(
report_bytes,
maintype="application",
subtype="pdf",
filename="audience-report.pdf",
cte="base64",
)
wire_bytes = message.as_bytes()
evidence = {
"wrapper_revision": "audience-wrapper-v1",
"attachment_sha256": digest,
"attachment_bytes": len(report_bytes),
"mime_bytes": len(wire_bytes),
}
return wire_bytes, evidence
The returned message contains the attachment. Passing those bytes into a durable job queue creates another stored copy if the queue persists its payload. Prefer a job that references the authorized report artifact, then construct the message near submission. That reduces retained payload, but it creates a dependency: the worker must still be able to fetch the artifact when a retry runs. Coordinate the artifact's deletion deadline with the job's retry deadline.
There is another trap here. A matching attachment digest does not imply an identical message. A wrapper edit changes the surrounding content, and MIME serialization can include generated boundary values. If exact wire reproduction is a requirement, retain the exact authorized message representation for its required lifetime. Calling a regenerated message an archive would hide the very evidence gap the archive is supposed to close.
Verify delivery without retaining the whole report
Sender authentication remains a separate concern from template custody. SPF, defined in RFC 7208, evaluates whether a sending host is authorized for the relevant SMTP identity. It does not authenticate the attachment's contents or guarantee inbox placement. DKIM provides a signature mechanism over selected message headers and the body; DMARC relates authentication results to the visible author domain. Evaluate the sending domain configuration alongside attachment handling. A correctly rendered report is of little use if its notification cannot be delivered.
Keep submission acceptance distinct from later delivery events. For an ambiguous timeout, reconcile using the interface's documented correlation or idempotency behavior before retrying. Do not assume every API provides the same protection. For a permanent rejection, preserve a minimal failure record and stop automatic retries under the workflow's policy. Repeatedly sending the same report is a poor substitute for understanding the event.
Test the lifecycle, including the uncomfortable cases: an attachment near the documented size limit, a wrapper revision changed between attempts, a report deleted before a queued retry, and a late failure event after the content retention window closes. Use synthetic reports. Deployment should preserve revision identifiers so an in-flight job's wrapper does not silently change during a release. Observability should expose queue age, submission outcomes, and deletion completion without placing rendered report content in routine logs.
Measure missing evidence too. A low retained-byte count is not useful if support cannot connect a report job to the delivery event that explains its failure.
Stop keeping content when its purpose ends
Choose the retention deadline from the report's purpose and the organization's applicable requirements; an email architecture cannot supply a universal legal duration. Apply that decision to the artifact, serialized messages, queue payloads, temporary files, and debug captures. Record how backup expiration affects the deletion timeline. An application delete operation alone does not describe every copy's lifetime.
The deliberate trade-off in this design is to stop keeping rendered bodies and attachment duplicates after their authorized operational window, while preserving only the approved minimal event evidence for its own defined period. That reduces the content available for a later investigation. After the report artifact expires, a digest and revision identifier may establish which artifact was intended, but support cannot inspect its contents, reproduce an exact send, or resend it without a new authorized generation step.
Accept that limitation explicitly. Template ownership is a retention decision as much as an editing decision: the team must know what it can reconstruct, what it can only correlate, and what it has chosen to forget.
Further reading
References:
- RFC 2045, MIME content-transfer encodings and base64 representation: https://datatracker.ietf.org/doc/html/rfc2045
- RFC 7208, Sender Policy Framework and its authorization scope: https://datatracker.ietf.org/doc/html/rfc7208
- RFC 6376, DomainKeys Identified Mail signatures: https://datatracker.ietf.org/doc/html/rfc6376
- RFC 7489, domain-based message authentication, reporting, and conformance: https://datatracker.ietf.org/doc/html/rfc7489
- Python email.message, message construction and attachments: https://docs.python.org/3/library/email.message.html
Top comments (0)