Constructing MHTML Files

Gabriela Peralta - Versasec
Gabriela Peralta - Versasec
  • Updated

Introduction

When sending automated or operator-driven email notifications, such as unblock cryptograms, temporary PINs, certificate lifecycle alerts, or self-service passphrases, vSEC:CMS supports two body content formats: plain text and HTML.

Using the HTML option requires importing a single-file web archive in MHTML format (.mht or .mhtml). Unlike standard .html files that rely on external asset hosting, an MHTML file encapsulates HTML markup, inline CSS styles, and MIME-encoded binary assets (such as corporate logos) into a single self-contained file.

Generating MHTML directly with AI development tools ensures cleaner MIME multipart structure, deterministic asset embedding, and strict compliance with email-safe HTML standards without the formatting bloat introduced by traditional desktop word processors.

Follow the instructions in this article for details on how to generate an MHTML email template containing dynamic vSEC:CMS variables using AI tooling and import it into the application.

Generate the MHTML Email Template Using AI Tools

AI code assistants, LLMs, or prompt-driven script generators can output fully compliant multipart/related MIME packages containing the HTML layout, base64-encoded images, and vSEC:CMS variable placeholders.

Structure of an MHTML File

An MHTML file requires standard MIME headers, a unique boundary delimiter, an HTML payload section, and binary parts for any embedded media:

For example:

From: <vSEC-CMS-Notification>
Subject: PIN Unblock Notification
MIME-Version: 1.0
Content-Type: multipart/related; boundary="----=_NextPart_01D9A4C0"

------=_NextPart_01D9A4C0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: Arial, sans-serif; color: #333333; margin: 0; padding: 20px; }
    .card { border: 1px solid #e0e0e0; border-radius: 6px; padding: 24px; max-width: 540px; }
    .code-box { background: #f4f6f8; font-size: 20px; font-weight: bold; letter-spacing: 2px; padding: 12px; text-align: center; margin: 20px 0; border: 1px dashed #0056b3; }
  </style>
</head>
<body>
  <div class="card">
    <img src="cid:company-logo" alt="Company Logo" width="160" />
    <h2>Credential Security Notice</h2>
    <p>Hello ${RecipientName},</p>
    <p>Your one-time unblock code has been generated. Use the code below to complete the credential unblock process:</p>
    <div class="code-box">${SelfServicePinUnblockCode}</div>
    <p>If you did not initiate this request, contact your security administrator immediately.</p>
  </div>
</body>
</html>

------=_NextPart_01D9A4C0
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-ID: <company-logo>
Content-Location: logo.png

iVBORw0KGgoAAAANSUhEUgAA...[BASE64_IMAGE_DATA]...==

------=_NextPart_01D9A4C0--

Generation Workflow

  1. Provide your layout requirements, corporate branding guidelines, and dynamic variables to the AI tool using a prompt structured around email client constraints:
    • MIME structure: Specify multipart/related format with boundary blocks.
    • Styling constraints: Request table-based email layouts or email-safe inline CSS; prohibit external fonts or remote CDN links.
    • Image handling: Request images to be embedded directly as separate MIME sections with unique Content-ID references (e.g., cid:logo), or convert assets to base64 data URIs.
    • Variables: Instruct the model to insert exact case-sensitive vSEC:CMS variables as unescaped literals (e.g., ${SelfServicePinUnblockCode}, ${RecipientName}, ${UserPin}).
  2. Validate that the dynamic placeholders match required vSEC:CMS variable names.
Important
Variable placeholders are case sensitive. If a variable is misspelled or cannot be resolved at runtime, vSEC:CMS outputs the raw placeholder text (e.g., ${UserPin}) rather than substituting the data.
 
  1. Save the model's generated raw text output into a plain text file with the extension .mhtml or .mht (ensure UTF-8 encoding).