Looping and conditions in email


Marketing dept at my company wants our system to send out an "order confirmation" email listing the products that were purchased as well as transaction details (coupon values applied, taxes, subtotals, totals, etc). Some transaction details will only be displayed in some emails where applicable.

Currently the system generates the content (HTML) of the email and it is just sent via SendGrid's SMTP (without using their templating system). Marketing wants to take control of the content via Hubspot and just have the system supply the data for the products and have Hubspot generate the content for the email so that Marketing can manipulate the look of the email without needing IT. This means that the template/email that Marketing creates need to support "looping" (to be able to get information about each product and generate the content for the product) as well as being able to hide content based on certain conditions.

How can this be accomplished in Hubspot email templates?


Hi @idimensionz, this can't be accomplished out of the box with HubSpot, but the Transactional Email API, and specifically the Single Send API can send an email after a purchase using our templates as well as custom properties from your external system along with HubSpot personalization tokens. Conditional statements using HubL cannot be used in the Marketing Email tool, as list segmentation and workflow automation handles most of the use cases for these scenarios.


Hi @Connor_Barley, thanks for the response.

We are using the Single Send API to send values to the email. The "Purchase Receipt" use case example under the Single Send API section of the Transactional Email API link you sent is what we are trying to accomplish. However I also saw the note under the Custom Properties section of the Single Send API link that states

Note: Custom properties do not currently support arrays. To provide a listing in an email, one workaround is to build an HTML list (either with tables or ul) and specify it as a custom property.

It seems to me that any company sending a receipt email would want to include at least some product details in the email which is really not currently possible since custom properties don't support arrays. We are already implementing a feature to send HTML via the API but this is not the best solution from Marketing's perspective because anytime they need to change the layout of the product information, they need to wait on IT to make the change to the HTML that is being sent via the API rather than being able to edit the email in Hubspot themselves without having to wait on IT.

Since this is something Hubspot has identified as a common use case, when will the ability to loop through arrays of custom properties and conditionally hide and display sections of an email be available?


Hi @idimensionz, I don't have a timeline for that functionality, but would be happy to send your feedback to our developers internally.


Hi @Connor_Barley, I stumbled upon this thread when searching for a solution for a similar problem. In my case we want to have invoice-related data in our transactional emails, but without support for arrays in the Custom properties and conditional statements we have to generate chunks of the emails on our side before passing them on to Hubspot, which is terribly inefficient, and in a way it's making us reconsider the use of the transactional email altogether. It would be a great improvement to have this fixed in the near future.


Hi @vicente.canhoto, thanks for responding here! I'll add your use case to our internal feedback tool. I'd also recommend posting this idea in our public Ideas forum here: https://community.hubspot.com/t5/custom/page/page-id/ideaslandingpage