Sending emails in Sitecore

Sometimes you need to send an email from your Sitecore code.

I’ve seen a ton of solution implementations where the developer have written some custom class that sends out emails using a SMTP client, good old classic ASP.NET. I myself  even wrote code for that in Sitecore solutions some years ago.

That was before I noticed the very simple method on the Sitecore.MainUtil class called SendMail.

The SendMail does exactly what you expect it to do.

The method takes a System.Net.Mail.MailMessage as argument and sends this using the SMTP client that has been configured in the standard Sitecore MailServer settings shown below.

The MainUtil class contain a lot of other old and fun methods that stood the test of time. For example the methods used for encode name replacements is in this class as well. It is well-worth a look if you haven’t looked at it already.

That was it for this post. I have one last Sitecore tip coming up today on creating custom caches in Sitecore.

Avatar photo

Anders Laub Christoffersen

Anders has been working with Sitecore for over a decade and has in this time been the lead developer and architect on several large scale enterprise solutions all around the world. Anders was appointed the title of Sitecore Technical MVP in 2014 and has been re-appointed the title every year since then.