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.

Anders Laub

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 has been nominated a Sitecore Technical MVP three years in a row for 2014, 2015 and 2016. Anders is now working as a Sr. Solutions Architect at Sitecore in Copenhagen.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website