Jump to Content
Blog Archive
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
newtelligence dasBlog 2.2.8279.16125
Email Me (Tim Gaunt)
© 2013 Tim Gaunt.
Sign In
One of the things that I've felt has always been a little lacking in uCommerce was their email system, it's a great idea and nicely implemented but it was rather inflexible in earlier version -you couldn't send "other" emails easily etc.
Most of these bug bears have now been resolved however I still feel that even the latest v1.5 release is a few lacking features that we have tended to build into our email systems by default:
In our recent project - www.ChalkboardsUK.co.uk, we extended the existing EmailService and "patched" the missing functionality. There's more we can (and will) do with this in the future but for now this should get you started.
By passing in a combination of QueryString and Placeholder parameters, you can send personalised emails to your customer e.g. have a subject line of "Your order with our store #1234" or start your email with "Dear John".
As well as enabling place holders it allows you to send your email to multiple recipients at the same time by simply separating the CC or BCC addresses with a semi-colon.
Finally (and I think this is pretty darn cool), it automatically tags the links within your email with the Google Analytics tracking code! By using the EmailProfile it will enable you to see whether customers are clicking through on links etc within your emails. Pretty cool eh!
We're open to your thoughts on this and ideas for moving it forward but at the moment, we will be adding functionality:
You can download the file right now by clicking here (TheSiteDoctor.UCommerce.EmailService.zip).
The use of this depends on your individual setup, in this post I'm going to assume you've got a separate assembly which you can include this in however I'll post another post soon which wraps this all up into a pipeline. We also use this for the customer "welcome" emails as well so we can send a pretty email welcoming them to the store.
Nothing needs to change in the way that you setup your emails in uCommerce. If you would like to send to multiple CC or BCC recipients, simply separate the addresses with a semi-colon (;) as you would in your standard email client:
If you want your content editors to be able to include properties from the order in your email, they'll need to use place holders. At present, the place holders are fairly limited in that there's no repeating regions etc. You can inject anything you want (you'll just need to add the key to dictionary of place holders when constructing the email. The user can then use that value in the email by surrounding the key with square braces e.g. [Order.Total].
Hi [Customer.FirstName] Thank you for your order of £[Order.Total] on [Order.Date]. The details of your purchase are below.
I would think the most common application for this at the moment will be within your own custom pipelines. If you've already used the UCommerce.Transactions.EmailService then you can retty much just replace the code. If you've not, here's an overview of how you can do it yourself:
// Create an instance of the EmailService var service = new TheSiteDoctor.uCommerce.Transactions.EmailService(); try { // Get the current catalog's email context var profile = SiteContext.Current.CatalogContext.CurrentCatalogSet.EmailProfiles.Single(); // Setup the QueryString Parameters for the page that's got the various content on -in this instance we're just getting an order confirmation so just pass in the order number Dictionary<string, string> qs = new Dictionary<string, string> { { "orderNumber", purchaseOrder.OrderGuid.ToString() } }; // Add the various bits of information you want to be able to pass to the content Dictionary<string, string> ph = new Dictionary<string, string> { { "Customer.FirstName", customer.FirstName }, { "Customer.LastName", customer.LastName }, { "Customer.EmailAddress", customer.EmailAddress }, { "Order.Number", purchaseOrder.OrderNumber }, { "Order.Date", purchaseOrder.CompletedDate.Value.ToShortDateString() }, { "Order.Total", purchaseOrder.OrderTotal.Value.ToString("f2") } }; // Send the email service.Send(profile, EmailTypeName, new MailAddress(customer.EmailAddress), qs, ph); } catch (Exception ex) { // Something "not good" happened so add any other info that might be of help // Add the customer data ex.Data.Add("Customer.FirstName", customer.FirstName); ex.Data.Add("Customer.LastName", customer.LastName); ex.Data.Add("Customer.EmailAddress", customer.EmailAddress); if (purchaseOrder != null) { ex.Data.Add("OrderId", purchaseOrder.OrderId); ex.Data.Add("Order.Number", purchaseOrder.OrderNumber); ex.Data.Add("BasketId", purchaseOrder.BasketId); } // Send/log your alert }
Don't forget to follow me on Twitter.
Remember Me