Complete Guide: Customizing Emails with HTML
This guide explains in depth how AdmCloud's Email Sending Formats work: the difference between the Visual editor and the HTML/Razor editor, what happens internally when an email is sent, how to create and configure a format, how to use the document's variables with examples, where to look up the available variables, how to test the result and how to make the format active. It's the email counterpart of the Printing Formats Guide; it shares the same engine and the same data model.
What it is and how it works under the hood
When AdmCloud emails an invoice, a quote, a purchase order, a statement, etc., it uses a default email body. An Email Sending Format lets you replace that standard body with your own: you design the email (with your logo, colors and text) and insert the document's real data (number, customer, total, etc.).
The full cycle is:
- You tie the format to a document type (the Object field). That type determines which data will be available: each document type has its own data "model", exactly as with printing formats.
- You write the email body, either with the Visual editor (drag and type) or with the HTML/Razor editor (code).
- You activate it as the default format for that document type (under Default Email Sending Formats).
- When the document is sent, AdmCloud loads the real document, builds its data model, compiles your format replacing each expression with the real value and uses the result as the email body.
Don't confuse this screen with two similar ones: Composing and Sending Emails is the window from which you send a one-off email (and can load a format to prefill it), and Default Email Sending Formats is where you assign which format is used by default for each document type. Here, in Email Sending Formats, is where you design and save the formats.
The two editor types
When creating a format you choose between two editors, and this decision determines what you can do and how the format is used:
| Editor | What it is for |
|---|---|
| Visual | A rich-text editor (word-processor style): you type, format, insert images and tables without touching code. Ideal for simple emails. It's the format type you can pick and load manually from the Composing and Sending Emails window. |
| HTML |
A code editor where you write HTML combined with Razor (@Model.Property),
with full control of the design and of the data inserted. It's the type meant to be
assigned as a document's default format, where
AdmCloud compiles it with Razor when sending.
|
Important difference: HTML formats assigned as defaults are processed with full Razor (conditionals, loops, value formatting). Visual formats loaded manually in the send window only do a simple variable substitution (which is why they don't support loops or conditionals). If you need logic —for example iterating an invoice's lines— use the HTML editor and assign it as default.
Language supported by HTML formats
HTML-type formats are written in HTML for the structure and styling, combined with Razor (the ASP.NET view syntax, based on C#) to insert data and apply logic. You can use:
- Any HTML and CSS: tables, images, inline styles or a
<style>tag, colors, fonts, etc. (aim for email-client-friendly HTML). - Data expressions with
@Model.Property(for example@Model.Relationship.Name). - Conditionals with
@if (...) { ... }. - Loops with
@foreach (var line in Model.Header.Items) { ... }. - Value formatting with .NET methods, for example
@Model.Header.DocDate.ToString("dd/MM/yyyy")or@Model.Header.TotalAmount.ToString("#,##0.00").
Since the body is an email with CSS styles, remember that a literal @ in CSS
(for example in @media) must be doubled (@@media) so Razor
doesn't mistake it for a data expression.
For security, a format's code can only read and display the document's data. The
system blocks saving if it detects instructions considered dangerous (database access, connection
strings, system configuration, etc.).
The code can only use what formats allow: it cannot read files, system variables or use reflection
(GetType(), typeof); if it tries, the system rejects saving (and the preview)
showing which element and on which line. Also, a format that takes more than 30 seconds (for example,
because of a loop that never ends) or a function that calls itself endlessly is stopped with an error
instead of being printed.
How to create a format, step by step
- Go to Email Sending Formats and use the New menu. You can pick Empty Email (Visual Editor), Empty Email (HTML Editor), or start from a ready-made sample format for a specific document (the list only shows the documents enabled in your plan).
- In Name, type a unique, descriptive name. Keep in mind the Name also acts as the suggested subject: when the format is loaded in the send window, its Name is placed in the email's Subject field. So use a name that works as a subject (for example, "Your invoice from [Company]").
- In Object, select the document type it applies to. It defines which variables you'll have available.
- Write the body in the matching tab: Body (Visual editor) or HTML Body (HTML editor). Lean on the sample template and on the Data Dictionary.
- Click Save.
- Activate it under Default Email Sending Formats for the matching document type. Until you assign it there, the saved format does not change the body of the emails.
How it is configured
| Field | What it is for |
|---|---|
| Name | Identifies the format in the list and when assigning it as a default. Required and unique. It is also used as the suggested subject when the format is loaded in the send window. |
| Object | Document type it applies to. Determines the available variables. |
| Type (Visual / HTML) | Editor and processing mode of the body (see above). |
| Body / HTML Body | The email content: rich text (Visual) or HTML + Razor code (HTML). |
| Owner | User responsible for the format. |
| Only allow the owner to access the structure | If on, only the Owner can view or edit the code; everyone else can only use the format if it's assigned as a default. |
The Model variables: how they work
The Model object represents the email's document. You access its data with
@Model. followed by the property name, chaining with dots:
@Model.Relationship.Name (the customer), @Model.CompanyInfo.CompanyName
(your company), @Model.Header.DocID (the document number). It's the same data
model the printing formats use, with a few email-specific
variables:
| Variable | What it holds |
|---|---|
Model.CompanyInfo | Your company's data: legal name, tax ID, address, phone numbers, email. |
Model.Relationship | The document's customer, vendor or contact (for example Model.Relationship.Name or Model.Relationship.EMail). |
Model.Header | The transaction header: number (DocID), date (DocDate), total (TotalAmount), etc. |
Model.Header.Items | The document's lines, to iterate with a loop (HTML formats only). |
Model.Logo | Your company's configured logo. |
Model.Message | The custom message the user types when sending the email. |
Model.Host / Model.HostName | The system's address, useful to build links back into AdmCloud. |
Model.CreditCardPaymentLink | Credit-card payment link (on documents that support it), so the customer can pay from the email. |
Variable names are case-sensitive and are always prefixed with
Model.. A misspelled or non-existent name for the selected Object produces an error
when sending.
Sample HTML format
This is a simple email body for sending a credit invoice. It shows the logo (or the company name), a greeting with the user's custom message, and the receipt data:
<div style="font-family:Arial,sans-serif; color:#333;">
@if (Model.Logo != null)
{
<img src="@Model.Logo.URI" alt="Logo" style="max-height:60px;" />
}
else
{
<h2>@Model.CompanyInfo.CompanyName</h2>
}
<p>Dear @Model.Relationship.Name,</p>
@if (!string.IsNullOrEmpty(Model.Message))
{
<p>@Model.Message</p>
}
<p>
Please find attached invoice <strong>@Model.Header.DocID</strong>,
dated @Model.Header.DocDate.ToString("dd/MM/yyyy"),
for a total of @Model.Header.TotalAmount.ToString("#,##0.00").
</p>
@if (!string.IsNullOrEmpty(Model.CreditCardPaymentLink))
{
<p><a href="@Model.CreditCardPaymentLink">Pay online</a></p>
}
<p>Best regards,<br />@Model.CompanyInfo.CompanyName</p>
</div>
The exact property names vary by document. Always confirm them in the Data Dictionary of the document type before assuming them.
Where to look up the available variables
Email Sending Formats do not have their own data dictionary or preview; they share the data model with printing formats, so you look up the variables there:
- Open the same document type in HTML Printing Formats and use its Data Dictionary tab to see the name and type of each property.
-
Or check the HTML Variables for Printing Formats screen (address
/PFDocumentation), which documents, document by document, each field and its type. -
Also remember the email-specific variables listed above (
Model.Message,Model.Host,Model.CreditCardPaymentLink,Model.Logo).
How to test the result
Unlike printing formats, the Email Sending Formats screen has no live preview. The recommended way to test a format is:
- Save the format.
- Go to a real document of that type and email it, manually choosing your format in the Composing and Sending Emails window (ideally to your own address).
- Review the received email and adjust the format if needed, before assigning it as the default.
In the send window, when you load an HTML-type format, the editor becomes read-only so its design isn't damaged; Visual formats can be edited there before sending.
Activating the format and other options
- Activate it per document: assign it under Default Email Sending Formats, which has a slot for each document type (credit invoice, cash invoice, notes, quote, order, purchase order, statement, payment voucher, service requests, time off, etc.).
- Status-change notifications: a format can be attached to the email notification of a document status change (for example, in service requests).
- Plugins: a format can be bundled into a published Plugin.
- Access control by Owner, with the option to restrict editing and viewing of the code to that person only.
- Transfer to another company you administer (requires the Enterprise edition with the "Create Plugins" feature).
The default assignment is at the company level (there is no per-subsidiary assignment as there is with printing formats). If a document has no format assigned, AdmCloud uses the system's standard email body.
Tips and common mistakes
Always start from a sample format for the document you need (the "New" menu) instead of from scratch: it already has a tested email structure and the most common variables in use.
Does the email arrive with an error or with raw @Model... text left
unreplaced? Check that each @Model.Property exists for the selected Object
(look it up in the Data Dictionary), that the @ in your CSS is doubled
(@@media) and that the format is HTML-type if you use loops or conditionals.
Did you save the format but emails still go out with the old body? You still need to assign it under Default Email Sending Formats for the document type; saving the format on its own does not activate it.