Twisted Bits

a blog by jeff lafay, software developer

My New Year Resolution is Better than Yours

Why are my resolutions better than yours? Because they're super awesome, that's why!

[ more ]

SMTP Debugging with Python

This is something that can be added to your developer bag of tricks, tool box, or whatever else you prefer to keep handy dev tools in.

We write lots of code and lots of apps. It's really nice to get notifications when things go south or when we need to send users notifications for various reasons (registration, social activity, etc.).

However, debugging emails or preventing emails from being sent out to users while we're developing can sometimes take a little more work and configuration than we'd like. 

I use a couple of methods when developing apps to prevent emails from leaving my machine and so I can inspect email output.  If you have python installed on your machine, this can be used in conjunction with any app that your developing.

[ more ]

Leveraging Razor for Email Content Templating

Razor provides a nice, clean template syntax. It works well for MVC apps and as I'll show you in this blog post, it works well for email message templating too. The basis of this blog post is a question on StackOverflow that I answered. Building email message content via string concats can be a huge pain to implement (not to mention pretty boring). 

My method for email templating with C# is sweet and simple. It works by reading the text from a template file at runtime, retrieving a model object, and then passing both to the Razor parser to render the needed email body with the model property values populated. Since the templates are read at runtime, small cosmetic tweaks to your email templates are easy.  

Here's a breakdown of what you need 

  • Reference RazorEngine (Nuget package available)
  • Create a template file
  • Render email body with RazorEngine's parser
  • profit!

[ more ]