Sending E-mail using Ucommerce
Any good e-commerce solution lets the store owner stay in contact with customers. One of the most well established ways of doing this is using the tried and true e-mail. As with any part in Ucommerce, you may choose to use the default built-in way of sending emails, or you can connect to any 3rd-party email provider of your choice.
In this article we'll focus on the default way of sending emails.
Steps Involved in Sending E-mail
To send e-mail you’ll need to:
- Add the types of e-mails you’ll be working with in Ucommerce
- Set up a profile for your store to use
- Configure the actual e-mails and their templates
- Configure your store to use that profile
- And finally trigger the e-mail
Adding a New E-mail Type
Ucommerce employs the notion of E-mail Types, which are your basic kinds of e-mails that you’re working with. Out of the box a single type is supplied called “order confirmation”, but you can configure your own types as needed.
Other types might include “Welcome new customer”, “Thank you signing up to the newsletter”, or more business-like type e-mails like “Your items are shipping” or “Invoice”.
To set up a new e-mail type you need to go to Settings => E-mail => Types, right click Types, and click Create.
Add an E-mail Profile
“What’s an E-mail Profile and why do we need one?”, you might ask.
Ucommerce supports multiple stores in a single installation and these stores might vary wildly in look and feel so we needed a way to set up multiple instances of the same e-mails on a per store basis to match that same look and feel from store on e-mails across different stores, e.g. an invoice for Store A might have a different look and feel than an invoice for Store B. Thus the notion of an E-mail Profile was introduced to group e-mail instances together for use on individual stores.
As you can see from the screenshot below the profile has an e-mail instance associated per e-mail type created previously. The difference being that for an E-mail Profile we’re dealing with an actual e-mail while an E-mail Type is a placeholder. The system basically ensures that we’re dealing with the same e-mail setup across all stores and makes it easier to deal with in code.
The process of creating a new profile is the same as you just used to create an E-mail Type.
Create the E-mail Content
Email content in Ucommerce is created as a regular (hidden) page within the CMS. For each type of email you're interested in sending, there'll be a corresponding page in the CMS. The CMS will then be requested for the particular page, and the email content is scraped via an internal http request. Typically you'll have the context needed as querystring parameters within the page request itself. This allows you to use your favorite tech stack (SPA or MVC) to render the content as a regular page. Each e-mail is language enabled so if you need multiple language variations of your e-mail you can set up a content node for each language you wish to support.
In each template you're typically interested in sending an email associated with an order. Ucommerce will add the OrderGuid parameter and you can then use the following code snippet to load the order and render the content needed.
string orderGuidParameterFromQueryString = System.Web.HttpContext.Current.Request.QueryString["OrderGuid"]; transactionLibrary.GetPurchaseOrder(Guid.Parse(orderGuidParameterFromQueryString));
Configure Contents of E-mail
Going back to Ucommerce you need to specify which content node Ucommerce is to use when generating the e-mail.
First you’ll set up the basics of the e-mail such as the name the e-mail is coming from and sender address and optionally whether the e-mail is to CC or BCC’d to anyone, e.g. stores owners like to get an e-mail notification when new orders roll in and this is the perfect use case for CC and BCC.
Next up you’ll configure the multilingual pieces of the e-mail like the subject and the contents of the e-mail, which you set up in a earlier step.
Select the template in the CMS using the content picker. Please note that this might be any content node; OrderConfirmation is used only as an example.
You can specify dynamic subjects of your e-mails, which are populated by the e-mail parameters sent to the e-mail service. To do this you use the e-mail parameters surrounded "{}", so to use the "ordernumber" parameter you specify "{ordernumber}" in the subject line.
You can specify additional parameters for the EmailService
when calling it from .NET. This is covered in the next section.
Configure Your Store to use an E-mail Profile
Once you’re happy with the e-mails in your installation you’re ready to tell your store to use those e-mails. To do so go to Product Catalog =>
With this step completed Ucommerce will know which e-mail and template to select when you ask it to send a particular e-mail type in a given store. More on that in the next step.
Wrap Up
The process of sending e-mail with Ucommerce does require a couple of steps to get going, however, in return you get the full power of the CMS to fully style your e-mails thus avoiding to have to learn some arcane templating system.
In addition you can even take advantage of some more advanced macros within Ucommerce. Think of the value of sending out your order confirmation e-mail, not only with the details of the order, but with added information about related items to each item bought or special offers tailored to the customer.
This is the value of having the CMS and Ucommerce handle your store e-mails.