Link Search Menu Expand Document

Message Templates

A message template defines the content of an email. It is similar to a transformation template in the sense that it uses the same Razor view engine. For each template, you can specify whether the output is HTML or plain text. Within the template, you can use various properties of the customer (that the email will go out to), such as their name, their unique customer code, and any associated metadata.

In a message template the main using definition is

@using Billing.Transformations.V1

Subsequently, your Model now contains a Customer and AttachedInvoices: a list of Invoices that are attached to the message. 

A Customer has the following relevant properties: CustomerName CustomerCode ContactName LCID -> Language code, can be used to condition on and create e-mails in different languages. EmailAddresses -> List of Emailadresses. Every Emailadress has a Key, Email, and DisplayName. Key is the identifier, Email is the address, and DisplayName is the name displayed in e-mail clients.

Every Invoice in the list AttachedInvoices has the following relevant properties: InvoiceNumber ApprovalDate BillingPeriodStart BillingPeriodEnd InvoiceItems -> A list of results on the invoice.

An InvoiceItem has an InvoiceRuleResult, which in turn has the following relevant properties: Quantity MeasuredQuantity Value ProductTagName BillingOutputTags

Putting it all together this can be used like this:

@using Billing.Transformations.V1
@{
  var invoice = Model.AttachedInvoices.FirstOrDefault();
}
<html>
@if (invoice != null){
  <body>
    <p>
      Dear @(Model.Customer.CustomerName),
    </p>
    <p>
     Attached you will find your invoice over the period @(invoice.BillingPeriodStart.ToString("Y")). The invoice total is @(invoice.InvoiceItems.Where(iit => iit.InvoiceRuleResult.BillingOutputTags.Contains("totalInclVAT")).Sum(iit => iit.InvoiceRuleResult.Value)).
    </p>
    <p>
      Kind regards,<br/>
      Company
    </p>
  </body>
}
</html>

Copyright Ⓒ 2023 CloudBilling (Inter8-NL B.V.)