gjshah7254
5/12/2014 - 11:22 PM

Send email via kentico email engine/template/queue

Send email via kentico email engine/template/queue

//http://devnet.kentico.com/articles/sending-e-mails-using-api
//Simple Custom email send it via kentico email engine:
CMS.EmailEngine.EmailMessage em = new CMS.EmailEngine.EmailMessage();
em.EmailFormat = CMS.EmailEngine.EmailFormatEnum.Html;
em.From = "from@mail.com";
em.Recipients = "to@mail.com";
em.Subject = "Subject";
em.Body = "body of email";

//CMS.EmailEngine.EmailSender.SendEmail("site_name", em);
CMS.EmailEngine.EmailSender.SendEmail(em);

//Send an email using kentico email template
     EmailMessage msg = new CMS.EmailEngine.EmailMessage();
     EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("EmailTemplateCodeName", CMSContext.CurrentSiteID);
 
     MacroResolver mcr = new MacroResolver();//kentico 7
     mcr.SpecialMacros = new String[,] { { "macro", "text" } }; //here you can specify text for multiple macros specified in template //kentico 7
     
    var resolver = MacroResolver.GetInstance();//kentico 8
    resolver.SetNamedSourceData(new String[,] { { "macro", "text" } });//here you can specify text for multiple macros specified in template//kentico 8 Use the macro in email like this {#macro#}
 
     msg.EmailFormat = EmailFormatEnum.Both;
     msg.From = eti.TemplateFrom; //make sure this is specified in the template settings
     msg.Recipients = "name@domain.com";
     msg.Subject = eti.TemplateSubject;
 
     EmailSender.SendEmailWithTemplateText(CMSContext.CurrentSiteName, msg, eti, mcr, false); //if send immeditaley is true, e-mail queue is not used