Send email in Kentico 8.xx

This is an example method to send data in Kentico 8.xx

Send email method

using CMS.EmailEngine;

using CMS.EventLog;



public static class CustomClass

    public static void SendEmail(string EmailTemplateCode, MacroResolver mcr,string recipients)
        EmailMessage msg = new CMS.EmailEngine.EmailMessage();
        EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate(EmailTemplateCode, SiteContext.CurrentSiteID);       
        msg.EmailFormat = EmailFormatEnum.Both;
        msg.From = eti.TemplateFrom;
        msg.Recipients = recipients;
        msg.Subject = eti.TemplateSubject;

            EmailSender.SendEmailWithTemplateText(SiteContext.CurrentSiteName, msg, eti, mcr, true);
        catch (Exception ex)
            EventLogProvider.LogException(ex.Source, "SendEmail", ex);


How to call method

 MacroResolver mcr = new MacroResolver();
 mcr.SetNamedSourceData("DomainName", "http://" + SiteContext.CurrentSite.DomainName);
 CustomClass.SendEmail("EmailTemplateDemo", mcr, "emailaddress");

Email Template - EmailTemplateDemo 

<!DOCTYPE html>
<html xmlns="">
     <a href="{% DomainName %}">Website Name</a>   

Have a try.

Popular posts from this blog

Example to disable save as certain file type in SSRS Report Viewer

Phone book application example - Java

Modal Popup Message Box ASP.NEt C# Example