Monday, 9 February 2015

Send email in Kentico 8.xx

Leave a Comment
This is 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;

        try
        {
            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="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>
  <body>
     <a href="{% DomainName %}">Website Name</a>    
    Thanks.
  </body>
</html>


Have a try.

By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Turn off EventLogProvider from store update / delete / insert activity in Kentico

Leave a Comment
The event log stores information about all events that occur in the system. It is useful to view logged information if unwanted behavior occurs in the system and you want to find out where the problem originates or get additional details.

But, some activities you don't want to be stored in database while you are developing Custom Webpart . This is the way how to turn off the for a while in your custom code block.

Step by Step

  1.  Add "using CMS.Base;"
  2. Wrap your code block with this using block code.

    using (CMSActionContext ctx = new CMSActionContext())
    {
        ctx.LogEvents = false;
       //your action here.

    }

So anything code you put under comment "Your action" will not be recorded in Event Log table.

Have a try.

By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.