Transactional email integration template

Learn how to use the transactional email template to integrate with Composable Commerce.

Connect application templates are for development purposes. They require further customization before being used in production projects.

The transactional email integration template demonstrates how to automatically send emails that are triggered by specific actions or events within an application or website. These emails are called transactional because they are typically part of a transaction or action initiated by the user, such as registering an account, making a purchase, or requesting a password reset. In this article, you will learn how commercetools Connect can be used to implement a transactional email system using this template.

Implementation

Integrating an email service provider with commercetools Connect involves using Subscriptions and Messages. By subscribing to Messages, an application can receive notifications of specific events to trigger sending emails. Subscriptions use delivery guarantees to ensure receipt of Messages.

The diagram illustrates that during a user interaction in your store, a specific transaction is initiated. This can be registering as a Customer, or completing an Order. This action is processed by commercetools Composable Commerce and generates a Message, which is delivered by a Subscription to a Connect application. The Connect application then determines the type of email to send based on the Message type, and sends Customer/Order information to the email service provider for it to send an appropriate email.

Choose an email service provider

The first step is to choose an appropriate email service provider. Consider factors such as deliverability, ease of use, scalability, pricing, and the availability of APIs for integration. Most modern email services, like Mailgun, SendGrid, or Mailchimp, provide comprehensive APIs and SDKs for this purpose. Once you've selected an email service provider, set up and configure your account based on your requirements, such as API keys, templates, domains, and sender emails.

Understand Subscriptions and Messages

Messages represent a change or an action performed on a resource, for example a Customer or an Order. Previously, you needed to poll the Messages API to retrieve Messages, but now you can subscribe to them with a Subscription and retrieve Messages automatically.

commercetools Connect provides the ability to subscribe and respond to Messages with an event Connect application type. After creating an event Connect application, you can create and deploy a Connector that responds to Messages without needing to deploy any infrastructure or hosting.

Create a Connect application

The email integration template is a good starting point for developing a Connect application to send transactional emails. You can customize and extend the email integration template based on your specific needs. To complete the integration, you will need to implement the final API calls to your selected email service provider.

Within a Connect application, you can define postDeploy and preUndeploy scripts to register and deregister Subscriptions for the events required for your use case. commercetools Connect automatically executes these scripts during the deployment lifecycle. postDeploy is where your Connect application would subscribe to the following Messages to send each type of email:

Email typeMessage
Customer registrationCustomer Created
Email verificationCustomer Email Token Created
Password resetCustomer Password Token Created
Order confirmationOrder Created
Order fulfillment/cancellationOrder State Changed
Order shipmentOrder Shipment State Changed
Order refundReturn Info Set

You should take the time to become familiar with these Messages and their payloads, as they are crucial for obtaining the information that will be used by your email service provider to send the emails.

Customize and personalize

You can utilize the flexibility of templates provided by your email service provider to customize and personalize emails based on the recipient and context.

Conclusion

Integrating an email service provider with commercetools Composable Commerce using the transactional email integration template can enhance your application's capability to engage with customers effectively. These emails, with an 80-85% average open rate, are crucial during user interactions. By following the steps outlined above and following the best practices, you can set up a robust system for automatically sending transactional emails.