Create emails with programmable content

Last updated:

This feature is currently in beta. By using this functionality you agree to the developer beta terms. This guide refers to functionality available only through that beta. Opt-into the beta in your templates or modules.

APPLICABLE PRODUCTS
  • Marketing Hub
    • Professional or Enterprise

Using programmable content to personalize emails with data from your HubSpot account using HubL. If you have a Marketing Hub Professional subscription, you can use data from standard CRM objects, such as products.

If you have a Marketing Hub Enterprise subscription, you can use structured data sources such as HubDB tables and custom objects. This data can be filtered based on the contact properties of the recipient.

For example, a real estate website could have prospects fill out a form with their home needs. The form submission could then trigger a workflow that sends the prospect an email with homes they may be interested in.

This guide walks through how to create programmable email content using either a HubDB table or a custom object.

Before you begin

Before you start, you'll need to create:

1. Create a programmable email module

To create the email module to access your HubDB or custom object data:

  • In your HubSpot account, navigate to MarketingFiles and TemplatesDesign Tools.
  • In the upper left, click File, then select New file.
  • In the dialog box, select Module for the file type, then click Next. Then, select the Emails checkbox and enter a name for the file.
  • Click Create
  • To enable programmable email for the module:
    • In the inspector on the right, toggle the Enable module for programmable email beta switch on. programmable-email-switch0
  • You can also enable programmable email for a coded email template by adding isEnabledForEmailV3Rendering: true to the top of the file. 

    enable-design-manager-template-for-programmable-email

 

With the module created, you'll then add code to access either HubDB or custom object data. 

HubDB

The code below uses the hubdb_table_rows HubL function to retrieve all data from the table. This will list all the real estate properties in the email, outputting the details of each property along with their image.

HubL
{% set real_estate_listings = hubdb_table_rows(1234567) %} 

{% for home in real_estate_listings%}
    {{ home.address}} <br>
	{{ home.price }} <br>
	<img
	alt="{{ home.name }}"
	src="{{ home.hero_image.url }}"
	style="outline: none; max-width: 100%;"
	width="260px"
	/>
	<br>
	<hr>
{% endfor %}

To filter the data returned for each recipient, you can add a query parameter, which will filter results by the specified contact properties. View the full list of filter options.

HubL
{% set query = "price__lte="~contact.budget_max~"price__gte="~contact.budget_min~"&city="~contact.city~"&order=listing_name" %}
{% set real_estate_listings = hubdb_table_rows(1234567, query) %}

{% for home in real_estate_listings %}
  
	...

{% endfor %}

Custom object

The code below retrieves data from a custom object, returning values (e.g. location, price) stored in the custom object's properties.

HubL
{% set real_estate_listings = crm_objects("p2990812_Property", "listing_name,location, price, address, type") %}

{% for home in real_estate_listings.results %}
    {{ home.address}} <br>
	{{ home.price }} <br>
	<img
	alt="{{ home.name }}"
	src="{{ home.hero_image.url }}"
	style="outline: none; max-width: 100%;"
	width="260px"
	/>
	<br>
	<hr>
{% endfor %}

To filter the data returned for each recipient, you can add a query parameter, which will filter the results by the recipient's contact properties. View the full list of filter options.

HubL
{% set query = "price__lte="~contact.budget_max~"price__gte="~contact.budget_min~"&city="~contact.city~"&order=listing_name" %}
{% set real_estate_listings = crm_objects("p2990812_Property", query, "listing_name,location, price, address, type") %}
{% for home in real_estate_listings.results %}

  ...

{% endfor %}

2. Add the module to an email

With the module published, you'll now add it to the body of the drag and drop email.

  • In your HubSpot account, navigate to MarketingEmail.
  • Select the email that you created.
  • In the left sidebar, underContent, click More. Find your programmable email module, then drag it into the email body.
drag-and-drop-email-editor-more-modules

If you've set up the module to filter data by specific contact properties, the email preview will appear blank. This is because the email tool hasn't been set to preview the email by a specific contact.

To preview what the email will look like for a specific contact:

  • In the upper right, click Actions, then select Previewemail-actions-menu0
  • On the next screen, click the Preview as a specific contact dropdown menu, then select a contactpreview-email-as-specific-contact0

You should now see only the data relevant to the recipient, filtered by their contact properties.

Screenshot of Email Preview

It's important to always have fallback data to send in the case that there are no HubDB rows or custom object records that meet the criteria you've set. Otherwise, the recipient might receive a blank email.

This beta may cause issues with existing templates. It's important to test any changes thoroughly before publishing and sending a live email.

More HubDB focused tutorials

HubSpot Academy


Was this page helpful? *
This form is for feedback on our developer docs. If you have feedback on the HubSpot product, please share it in our Idea Forum instead.