Send for approval

Topics: General
Oct 25, 2011 at 12:55 PM

Hi All,

Should the "Send for approval" menu item send an e-mail?

If so how can I control which user(s) receive the e-mail?



Oct 25, 2011 at 1:53 PM
Edited Oct 25, 2011 at 1:54 PM

The way it is implemented now, it does not send any emails. In this discussion you can find the code that handles the event, and gets the list of uses that have "approve" right:


Here's also the code I used recently, e-mail is hardcoded here, but if you combine it with the code in the link above, it should do the work:


using System;
using System.Net.Mail;
using System.Web;
using Composite.Core;
using Composite.Core.Application;
using Composite.Data;
using Composite.Data.ProcessControlled.ProcessControllers.GenericPublishProcessController;
using Composite.Data.Types;

namespace App_Code.Notifications
    /// <summary>
    /// Class that sends "awaiting approval" notification emails 
    /// </summary>
    public class Approval
        private static readonly string EmailPageAvaitingApproval_To = "";
        private static readonly string EmailPageAvaitingApproval_From = "";
        private static readonly string EmailPageAvaitingApproval_Subject = "Page awaiting approval: '%title%'";
        private static readonly string EmailPageAvaitingApproval_Body =
@"Hi XXXXXXX<br/>
There's a new page that needs your approval<br/>
<a href=""%url%"">
Best regards<br/>
Notification robot @";

        public static void OnBeforeInitialize() { }

        public static void OnInitialized()
            DataEventSystemFacade.SubscribeToDataAfterUpdate<IPage>(MyPageAfterUpdate, true);

        private static void MyPageAfterUpdate(object sender, DataEventArgs dataEventArgs)
            IPage page = (IPage)dataEventArgs.Data;

            if (page.PublicationStatus != GenericPublishProcessController.AwaitingApproval)

            string pageUrl;

                using (var conn = new DataConnection(PublicationScope.Unpublished))
                    pageUrl = string.Format("http://{0}{1}", HttpContext.Current.Request.Url.Host, conn.SitemapNavigator.GetPageNodeById(page.Id).Url);
            catch (Exception ex)
                Log.LogError("Approval", "Failed to get page url");
                Log.LogError("Approval", ex);
                pageUrl = string.Empty;

            Func<string, string> formatEmail =
                text => text
                .Replace("%title%", page.Title)
                .Replace("%title_htmlencoded%", HttpContext.Current.Server.HtmlEncode(page.Title))
                .Replace("%url%", pageUrl)
                .Replace("%url_attributeencoded%", HttpContext.Current.Server.UrlEncode(pageUrl)); ;

            MailMessage mail = new MailMessage(
                IsBodyHtml = true

            SmtpClient smtp = new SmtpClient();
Oct 26, 2011 at 8:24 AM

Thanks, looks like that should do it.

Forgive me but I think I'm jumping in at the deep end here! Where should I put this code?

Oct 26, 2011 at 9:00 AM

>>  Where should I put this code?

I forgot to mention - create a *.cs file in "/App_Code" folder, or in a dll inside "/bin" folder. It will be executed since it has [Composite.Core.Application.ApplicationStartup] attribute on it

Jan 16, 2012 at 10:38 AM

I created a package for this functionality. It is better than suggested previously code since it a) does not send additional notification when a page is already in "waiting for approval" state b) Has an easier to edit email template


Way to setup:

1)      Download and install package

2)      Edit /App_Data/EmailTemplates/Notifications.PageAwaitingApproval.xml and specify email’s configuration – email’s content, recipient & sender e-mails.

 Default content looks like:

	<!-- Developer note:
	    	 Emails are comma separated, 
		 It is possible to reference settings from AppSettings by writing markup like {AppSetting:404Email.To} 
		 String parameters defined as {ParameterName}
		 Markup parameters defined as <render parameter="XmlParameterName" />
	<subject>Page awaiting approval: '{Title}'</subject>
			There's a new page that needs your approval<br/>
			<a href="{Url}">

			Best regards<br/>
			Notification service


If they want to send email to everybody who has right to approve, they should use code sample from this thread