1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Email Notification in sitefinity 3.7

Email Notification in sitefinity 3.7

15 posts, 0 answered
  1. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    02 Nov 2009
    Link to this post

     Hi,

    How to achieve the following in sitefinity 3.7 ?

    1) When a page is “sent for approval” by the “content editors”, an email should be sent to the “approvers” group.
    2) The email will contain a link to view the page in the CMS and also links to “approve” or “reject” the changes. In the CMS, this page needs to be seen as “waiting for approval” or similar.
    3) If the page is “approved”, the “publishers” need to be notified by email and a link to “publish” should be in the email.
    4) If the page is “rejected”, an email should be sent to the “content editor” notifying them why it was rejected, with a link to view the page in question.

    Thanks,
    Karnan

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    02 Nov 2009
    Link to this post
    Hi karnan sekar,

    Thank you for using our services.

    Can you take a look at the following KB article - How to notify roles that a page has been sent through workflow. It gives a step by step tutorial on how to enable e-mail notifications for different steps of the workflow.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    03 Nov 2009
    Link to this post
    Hi Radoslav Georgiev ,

    We did as per the below link
    How to notify roles that a page has been sent through workflow.

    In that class a line as below is there.

     public EmailActivity() { Status = ApprovalStatus.ForApproval; }

    How to fire
     
    Status = ApprovalStatus.Approved;
    Status = ApprovalStatus.Declined;

    and other is in the same class. Since the status will be always ApprovalStatus.ForApproval right.

    Thanks,
    Karnan



  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Nov 2009
    Link to this post
    Hi karnan sekar,

    In the CustomPageWorkflow class add the highlighted:
    // Step 2: wait for denial or approval 
    //****************************************************************** 
     
    listen = Activity.Load<ListenActivity>(base.Transaction);
    base.AddActivity(listen);
     
    eventActivity = Activity.Load<EventActivity>(base.Transaction);
    eventActivity.Caption = "Approve";
    eventActivity.CommandName = "Approve";
    listen.AddActivity(eventActivity);
     
     
    setStatus = Activity.Load<SetApprovalStatusActivity>(base.Transaction);
    setStatus.ApprovalStatus = ApprovalStatus.Approved;
    eventActivity.AddActivity(setStatus);
    //add email activity when approved
    emailActivity.WorkflowID = base.ItemId;
    emailActivity.Status = ApprovalStatus.Approved;
    eventActivity.AddActivity(emailActivity);
     
    eventActivity = Activity.Load<EventActivity>(base.Transaction);
    eventActivity.Caption = "Decline";
    eventActivity.CommandName = "Decline";
    listen.AddActivity(eventActivity);
     
    setStatus = Activity.Load<SetApprovalStatusActivity>(base.Transaction);
    setStatus.ApprovalStatus = ApprovalStatus.Declined;
    eventActivity.AddActivity(setStatus);
    //add email activity when declined
    emailActivity.WorkflowID = base.ItemId;
    emailActivity.Status = ApprovalStatus.Declined;
    eventActivity.AddActivity(emailActivity);

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    03 Nov 2009
    Link to this post
    Hi Radoslav Georgiev,

    How to send the  "exact page URL" to the approver to approve. Since site has many pages, the approver can't check which page to be approved.

    Presently we are getting a mail as below.

    The 'addthis' page has been sent for approval. To approve the page, please go to URL: http://sitefinitysite/Sitefinity/Admin/Pages.aspx

    Please give us solution.

    Thanks,

    Karnan

  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Nov 2009
    Link to this post
    Hello karnan sekar,

    You can get the default url for a page (this is a property of a page). when you get it it will return a relative path like (~/pageforaproval.aspx), then you can add this to the query string when you contruct the link ?cmspagemode=edit, and form the url like http://sitefinitysite/pageforaproval.aspx?cmspagemode=edit this will take you to the edit mode of the page:
    string relativeurl = page.DefaultUrl.Url;
    mailMsg.Body += String.Format("The '{0}' page has been approved. To approve the page, please go to URL: http://{1}{2}?cmspagemode=edit", page.Name, System.Web.HttpContext.Current.Request.Url.Host,relativeurl.Substring(1));

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    03 Nov 2009
    Link to this post
    Hi Radoslav Georgiev,

    It is relative URL working good. but after adding the below in the class "the mail for is not going" for all status.

    //add email activity when approved
    emailActivity.WorkflowID = base.ItemId;
    emailActivity.Status = ApprovalStatus.Approved;
    eventActivity.AddActivity(emailActivity);

    //add email activity when declined
    emailActivity.WorkflowID = base.ItemId;
    emailActivity.Status = ApprovalStatus.Declined;
    eventActivity.AddActivity(emailActivity);

     Below is the two class which we added, please check it and tell us what went wrong.
     


    using System;
    using System.Collections.Generic;
    using System.Web;
    using Telerik.Workflow;
    using Telerik.Cms;
    using System.Net.Mail;


    public class CustomPageWorkflow : PageWorkflow
    {
        protected override void LoadActivities()
        {
            // Step 1: wait to send for approval  
            //****************************************************************  
            ListenActivity listen = Activity.Load<ListenActivity>(base.Transaction);
            base.AddActivity(listen);

            EventActivity eventActivity = Activity.Load<EventActivity>(base.Transaction);
            eventActivity.Caption = "Send for approval";
            eventActivity.CommandName = "SendForApproval";
            listen.AddActivity(eventActivity);

            SetApprovalStatusActivity setStatus = Activity.Load<SetApprovalStatusActivity>(base.Transaction);
            setStatus.ApprovalStatus = ApprovalStatus.ForApproval;
            eventActivity.AddActivity(setStatus);

            //we want an email to go to the approvers when a page is sent for approval   
            //add the eMail activity to the event           
            EmailActivity emailActivity = Activity.Load<EmailActivity>(base.Transaction);
            emailActivity.WorkflowID = base.ItemId;
            emailActivity.Status = ApprovalStatus.ForApproval;

            eventActivity.AddActivity(emailActivity);

            // Step 2: wait for denial or approval  
            //******************************************************************  

            listen = Activity.Load<ListenActivity>(base.Transaction);
            base.AddActivity(listen);

            eventActivity = Activity.Load<EventActivity>(base.Transaction);
            eventActivity.Caption = "Approve";
            eventActivity.CommandName = "Approve";
            listen.AddActivity(eventActivity);

            setStatus = Activity.Load<SetApprovalStatusActivity>(base.Transaction);
            setStatus.ApprovalStatus = ApprovalStatus.Approved;
            eventActivity.AddActivity(setStatus);

            //add email activity when approved
            emailActivity.WorkflowID = base.ItemId;
            emailActivity.Status = ApprovalStatus.Approved;
            eventActivity.AddActivity(emailActivity);


            eventActivity = Activity.Load<EventActivity>(base.Transaction);
            eventActivity.Caption = "Decline";
            eventActivity.CommandName = "Decline";
            listen.AddActivity(eventActivity);

            setStatus = Activity.Load<SetApprovalStatusActivity>(base.Transaction);
            setStatus.ApprovalStatus = ApprovalStatus.Declined;
            eventActivity.AddActivity(setStatus);

            //add email activity when declined
            emailActivity.WorkflowID = base.ItemId;
            emailActivity.Status = ApprovalStatus.Declined;
            eventActivity.AddActivity(emailActivity);



            // Step 3: check condition  
            //*********************************************************************  

            IfElseActivity ifElse = Activity.Load<IfElseActivity>(base.Transaction);
            ifElse.InterfaceType = typeof(CmsWorkflowService);
            ifElse.MethodName = "IsApproved";
            ifElse.Parameters = new object[] { base.ItemId };
            base.AddActivity(ifElse);

            ConditionActivity trueActivity = Activity.Load<ConditionActivity>(base.Transaction);
            trueActivity.Condition = true;
            ifElse.AddActivity(trueActivity);

            ConditionActivity falseActivity = Activity.Load<ConditionActivity>(base.Transaction);
            falseActivity.Condition = false;
            ifElse.AddActivity(falseActivity);


            // Step 4: wait to publish  
            //*********************************************************************  

            listen = Activity.Load<ListenActivity>(base.Transaction);
            trueActivity.AddActivity(listen);

            eventActivity = Activity.Load<EventActivity>(base.Transaction);
            eventActivity.Caption = "Publish";
            eventActivity.CommandName = "Publish";
            listen.AddActivity(eventActivity);

            CallExternalMethodActivity callMethod = Activity.Load<CallExternalMethodActivity>(base.Transaction);
            callMethod.InterfaceType = typeof(CmsWorkflowService);
            callMethod.MethodName = "PublishPage";
            callMethod.Parameters = new object[] { base.ItemId };
            eventActivity.AddActivity(callMethod);

            setStatus = Activity.Load<SetApprovalStatusActivity>(base.Transaction);
            setStatus.ApprovalStatus = ApprovalStatus.Published;
            eventActivity.AddActivity(setStatus);
        }
    }


    using System;
    using System.Collections.Generic;
    using System.Web;
    using Telerik.Workflow;
    using Telerik.Cms;
    using System.Net.Mail;

    /// <summary>
    /// Summary description for EmailActivity
    /// </summary>
    /// <summary>
     
    public class EmailActivity : Activity
    {

        public EmailActivity()
        {
            Status = ApprovalStatus.ForApproval;
            

        }



        public ApprovalStatus Status;
        private Guid workflowID;


        //Every workflow request has an ID. Get that ID.
        public Guid WorkflowID
        {
            get
            {
                object value = base.GetValue("WorkflowID");
                return value != null ? (Guid)value : Guid.Empty;
            }
            set
            {
                base.SetValue("WorkflowID", value);
            }
        }


        public override ActivityExecutionStatus Execute(WorkflowRuntime runtime)
        {
            //Get the workflow ID, so you can get the row in the database for it
            CmsManager manager = new CmsManager();
            ICmsPage page = manager.Provider.GetPageByWorkflow(this.WorkflowID);

            //send an email   
            MailMessage mailMsg = new MailMessage();

            // Subject and Body      
            switch (Status)
            {
                //Send a message based on status. If the page is approved, then send a message that is has been approved
                case ApprovalStatus.Approved:
                    mailMsg.Subject = "page approved";
                    mailMsg.Body += String.Format("The '{0}' page has been approved. To approve the page, please go to URL: http://{1}/Sitefinity/Admin/Pages.aspx", page.Name, System.Web.HttpContext.Current.Request.Url.Host);
                    break;
                case ApprovalStatus.Archived:
                    break;
                //If declined, then send a message that it has been declined
                case ApprovalStatus.Declined:
                    mailMsg.Subject = "page declined";
                    mailMsg.Body += String.Format("The '{0}' page has been declined.");
                    break;
                case ApprovalStatus.Draft:
                    break;
                //If it is for approval, then send a message saying it has been for approval
                case ApprovalStatus.ForApproval:
                    mailMsg.Subject = "page pending approval";
                    string relativeurl = page.DefaultUrl.Url;
                    mailMsg.Body += String.Format("The '{0}' page has been approved. To approve the page, please go to URL: http://{1}{2}?cmspagemode=edit", page.Name, System.Web.HttpContext.Current.Request.Url.Host, relativeurl.Substring(1));

                    break;
                case ApprovalStatus.None:
                    break;
                case ApprovalStatus.Published:
                    mailMsg.Subject = "page pending approval";
                    mailMsg.Body += String.Format("The '{0}' page has been published. To view the page, please go to this URL: http://{1}/{2}.aspx", page.Name, System.Web.HttpContext.Current.Request.Url.Host, page.Name);
                    break;
                default:
                    break;
            }
            if (!mailMsg.Subject.Equals(string.Empty))
            {
                // To     
                string approversRole = "administrators";
                string[] usernames = Telerik.Security.UserManager.Default.GetUsersInRole(approversRole);
                //For every user, send him or her an e-mail
                foreach (string username in usernames)
                {
                    System.Web.Security.MembershipUser user = Telerik.Security.UserManager.Default.GetUser(username);
                    mailMsg.To.Add(user.Email);
                }

                // Init SmtpClient and send      
                SmtpClient smtpClient = new SmtpClient();
                if (mailMsg.To.Count <= 0)
                    mailMsg.To.Add(mailMsg.From);

                smtpClient.Send(mailMsg);
            }

            return base.Execute(runtime);
        }
        /// <summary>  
        /// Summary description for CustomPageWorkflow  
        /// </summary>  
        ///  

    }



    Thanks,
    Karnan


  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Nov 2009
    Link to this post
    Hello karnan sekar,

    Create two more email activity classes (one for approved and one for declined), sample for approved bellow:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using Telerik.Workflow;
    using Telerik.Cms;
    using System.Net.Mail;
     
    /// <summary>
    /// Summary description for EmailActivity
    /// </summary>
    /// <summary>
     
    public class EmailActivityApproved : Activity
    {
        public EmailActivityApproved()
        {
            Status = ApprovalStatus.Approved;
        }
        ...
    }

    Then in the custom page workflow class add this too:
    // Step 2: wait for denial or approval 
    //****************************************************************** 
     
    listen = Activity.Load<ListenActivity>(base.Transaction);
    base.AddActivity(listen);
     
    eventActivity = Activity.Load<EventActivity>(base.Transaction);
    eventActivity.Caption = "Approve";
    eventActivity.CommandName = "Approve";
    listen.AddActivity(eventActivity);
     
    setStatus = Activity.Load<SetApprovalStatusActivity>(base.Transaction);
    setStatus.ApprovalStatus = ApprovalStatus.Approved;
    eventActivity.AddActivity(setStatus);
     
    //add email activity when approved
    EmailActivityApproved approvedEmailActivity = Activity.Load<EmailActivityApproved>(base.Transaction);
    approvedEmailActivity.WorkflowID = base.ItemId;
    emailActivity.Status = ApprovalStatus.Approved;
    eventActivity.AddActivity(approvedEmailActivity);

    Remove the code from above code that did not work, with three types of email activities it will work for sure.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    04 Nov 2009
    Link to this post
    Hi Radoslav Georgiev ,

    Thank you so much mail sending is working fine. Still some issues in passing URL
    string relativeurl = page.DefaultUrl.Url;
    mailMsg.Body += String.Format("The '{0}' page has been approved. To approve the page, please go to URL: http://{1}{2}?cmspagemode=edit", page.Name, System.Web.HttpContext.Current.Request.Url.Host,relativeurl.Substring(1));

    If we send mail for " page pending approval "(ForApproval)  the link the directing to the current page. But still the " Send for approval" button is coming for an Approver (Admin). Here the approver don't need click send for approval button again. Since the approver(admin) will receive a mail again saying page pending approval.

    Please tell us how to hide the "send for approval" button when approver comes for approve or decline.

    Thanks,
    Karnan
     
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Nov 2009
    Link to this post
    Hi karnan sekar,

    1. You can send the message to the admin only in case the object is sent for Approval and it should be approved.

    2. The following string which you have typed - http://{1}{2}?cmspagemode=edit will redirect you to page edit mode directly, not to the pages waiting for approval.

    3. To hide the button you can check the currently logged in user and if it is an admin and the approval status of the object.

    below is a sample code that you should modify:

    protected override void OnPreRender(EventArgs e)
       {
           base.OnPreRender(e);
           CmsManager manager = new CmsManager();
           Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;
           ICmsPage currentPage = (ICmsPage)manager.GetPage(pageID, true);
           WorkflowInstance wInstance = currentPage.GetWorkflow();
           PageWorkflow activity = (PageWorkflow)wInstance.Activity;
           if (activity.ApprovalStatus == ApprovalStatus.ForApproval && UserManager.IsCurrentUserInRole("administrators"))
           {
             workflow.Visible = false;
             // DO SOMETHING ELSE
           }

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    04 Nov 2009
    Link to this post
    Hi Ivan Dimitrov,

    In which page we need to write
    protected override void OnPreRender(EventArgs e)


    Thanks,
    Karnan
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Nov 2009
    Link to this post
    Hi karnan sekar,

    You can modify Sitefinity/Admin/ControlTemplates/Pages/PageViewer.ascx.cs

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    04 Nov 2009
    Link to this post
    Hi Ivan Dimitrov,

    Since we are working in sitefinity 3.7  We followed the link given by Radoslav Georgiev as below.
    How to notify roles that a page has been sent through workflow
    Presently the file Sitefinity/Admin/ControlTemplates/Pages/PageViewer.ascx.cs which you mentioned is not there in the location.
    Shall we create PageViewer.ascx.cs in the specific location and write the OnPreRender.

    Thanks,
    Karnan

  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    04 Nov 2009
    Link to this post
    Hello karnan sekar,

    Create a code behind of the control template and add the logic there.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  15. karnan sekar
    karnan sekar avatar
    80 posts
    Registered:
    07 Jul 2009
    04 Nov 2009
    Link to this post

    Hi IIvan Dimitrov,


    We have created PageViewer.ascx.cs  and added the OnPreRender. But by clicking a page , it gives a error as below.
    Please help us.

    Server Error in '/' Application.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error: 

    Line 23:         ICmsPage currentPage = (ICmsPage)manager.GetPage(pageID, true);
    Line 24:         WorkflowInstance wInstance = currentPage.GetWorkflow();
    Line 25:         PageWorkflow activity = (PageWorkflow)wInstance.Activity;
    Line 26:         if (activity.ApprovalStatus == ApprovalStatus.ForApproval && UserManager.IsCurrentUserInRole("administrators"))
    Line 27:         {

    Source File: d:\Program Files\telerik\Sitefinity3.2\WebSites\Test_Sitefinity37\Sitefinity\Admin\ControlTemplates\Pages\PageViewer.ascx.cs    Line: 25 

    Stack Trace: 

    [NullReferenceException: Object reference not set to an instance of an object.]
       Sitefinity_Admin_ControlTemplates_Pages_PageViewer.OnPreRender(EventArgs e) in d:\Program Files\telerik\Sitefinity3.2\WebSites\Test_Sitefinity37\Sitefinity\Admin\ControlTemplates\Pages\PageViewer.ascx.cs:25
       System.Web.UI.Control.PreRenderRecursiveInternal() +80
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

    Thanks,
    Karnan
Register for webinar
15 posts, 0 answered