Generating HTML emails with RazorEngine - Part 04 - Taking a step back: behind the scenes of Razor and RazorEngine

This is the fourth part of a 10-part blog series. You'll find a list of all the posts in this series in the introductory post. Make sure to review the Before we start section in the introductory post. All the source code is on GitHub. Comment? Bug? Open an issue on GitHub. Before diving any deeper into RazorEngine, it's worth spending a few minutes getting a good grasp of what Razor and RazorEngine really are and of how they work under the hood. It will save a lot of time and frustration when trying to customize or understand RazorEngine's behaviour. This is a very quick and deliberately simplified overview of Razor. What is Razor? Razor is a language that lets you create document templates mixing static markup and code. Typically, the static markup is HTML and the code is C# or VB.NET. But it doesn't have to be. Razor … [+]
Read more

A tale of debugging - the LinkedIn API, .NET and HTTP protocol violations

In my last project, I was in charge of integrating the LinkedIn API into .NET 4 application. A few weeks after launch and during a client demo (of course), a request to the LinkedIn API failed with the following cryptic WebException: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF We had thouroughly tested the LinkedIn API over several months before launch, had a dedicated team of testers and had a full suite of automated integration tests against the API, yet had never seens this error before. In fact, I'd never seen this error before in my life - and I've implemented my fair share of third-party REST API integrations. Since we were investigating another issue at the time, we put that one down on a temporary network glitch and moved on... ...until both our QA team and our automated tests were able to … [+]
Read more

Generating HTML emails with RazorEngine - Part 03 - Caching, VS integration & namespace config

This is the third part of a 10-part blog series. You'll find a list of all the posts in this series in the introductory post. Make sure to review the Before we start section in the introductory post. All the source code is on GitHub. Comment? Bug? Open an issue on GitHub. Caching templates with RazorEngine When generating our email in the previous post, we happily ignored the cacheName parameter of the TemplateService.Parse() method. This was wrong. Not using RazorEngine's cache will result in both dreadful performances and memory leaks. Generating a document from a Razor template involves some very expensive operations. We'll cover this in more details in the next post but in a nutshell, TemplateService.Parse() will: Parse your template and generate the source code of a class that can generate the final document. Compile that class on the fly into its own assembly. Load that newly … [+]
Read more

Generating HTML emails with RazorEngine - Part 02 - Basics: generating your first email

This is the second part of a 10-part blog series. You'll find a list of all the posts in this series in the introductory post. Make sure to review the Before we start section in the introductory post. All the source code is on GitHub. Comment? Bug? Open an issue on GitHub. As indicated in the introductory post, we'll work from a console application. The email template For this example, we'll generate a simple Welcome email. We'll start with a basic model for our email: namespace ConsoleApplication.Models { public class UserModel { public string Name { get; set; } public string Email { get; set; } public bool IsPremiumUser { get; set; } } } We can then implement our email template in the same way as we would implement an ASP.NET MVC Razor view. Here, we'll use a strongly-typed model: @model ConsoleApplication.Models.UserModel <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/ … [+]
Read more

Generating HTML emails with RazorEngine - Part 01 - Introduction

Blog posts in this series: Introduction (this post) Basics: generating your first email More Basics: caching, VS integration & namespace configuration Taking a step back: what is Razor and what does RazorEngine actually do? URL generation & T4MVC integration with RazorEngine (TBD) Layout with RazorEngine (TBD) Partials with RazorEngine (TBD) On keeping your sanity: inlining CSS with PreMailer.Net (TBD) Getting a little help from CsQuery: including subject, sender and recipient information in your email templates (TBD) Putting it all together: building a complete email-generation library with RazorEngine, PreMailer.Net and CsQuery (TBD) I can think of few things in my life as a software developer that have caused me more grief than having to generate HTML emails. I long for the days when you could still argue in favour of plain text emails with clients. HTML emails are a strange kind of beast. On one side, they're part of … [+]
Read more

Ghost.io - the first blogging platform that makes me happy

Blogs have established themselves as one of the main building blocks of the web. Even though it's been a long time since having a blog was the latest fad among self-respecting hipsters, blogs are still just about everywhere. In fact, virtually everything you read on the web today is published as a blog post. So it boggles my mind that 16 years after the word Blog was coined, the most popular blogging platforms out there are still so goddamn awful - slow, bloated and clunky with dreadful text editors. So it has been a bit of a revelation when I discovered Ghost earlier this week through their annoucement of version 0.4. It's rare for me to instantly fall in love with a piece of software, especially an early beta one. But Ghost is one of those rare occasions. It's that good. And, yes, this blog is hosted on Ghost. … [+]
Read more