0

I have site policy which close and delete site automatically after 1 year from date of creation if not extended. It will also send an email notification to owner 3 months before site deletion .

I want change mail message in email notification. How can I do that ?

1 Answer 1

0

The following article explains how to update the email on a policy. We've adapted this for SharePoint Online, but the article is specifically for on prem. http://blogs.technet.com/b/tothesharepoint/archive/2013/03/28/site-policy-in-sharepoint.aspx

Relevant code provided by the author in the article:

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.InformationPolicy;
using System;

namespace SitePolicyEmailChanger
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteCollectionUrl = "";
            string relativeSiteUrl = "";

            // Get the site and web info
            Console.WriteLine("Site Policy E-mail Changer");
            Console.WriteLine("Enter the Site Collection URL: ");
            siteCollectionUrl = Console.ReadLine();
            Console.WriteLine("Enter the relative Site URL: ");
            relativeSiteUrl = Console.ReadLine();

            // Return the currently applied Site Policy
            ClientContext context = new ClientContext(siteCollectionUrl);
            Site site = context.Site;
            Web web = site.OpenWeb(relativeSiteUrl);
            ProjectPolicy policy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(context, web);
            context.Load(policy, 
                         p => p.Name, 
                         p => p.Description,
                         p => p.EmailSubject,
                         p => p.EmailBody, 
                         p => p.EmailBodyWithTeamMailbox);
            context.ExecuteQuery();

            // Display the current Site Policy properties and pause
            Console.WriteLine(String.Format("Policy Name is: {0}", policy.Name));
            Console.WriteLine(String.Format("Policy Description is: {0}", policy.Description));
            Console.WriteLine(String.Format("Policy E-mail Subject is: {0}", policy.EmailSubject));
            Console.WriteLine(String.Format("Policy E-mail Body is: {0}", policy.EmailBody));
            Console.WriteLine(String.Format("Policy E-mail Body (with Site Mailbox) is: {0}", policy.EmailBodyWithTeamMailbox));
            Console.WriteLine();
            Console.ReadLine();

            // Edit the Site Policy E-mail properties
            policy.EmailSubject = "Contoso Site Deletion Notice";
            policy.EmailBody = "The Contoso site <!--{SiteUrl}--> is set to expire on <!--{SiteDeleteDate}-->. If you have any questions or concerns, please contact your admin.";
            policy.EmailBodyWithTeamMailbox = "The Contoso site <!--{SiteUrl}--> associated with Site Mailbox <!--{TeamMailboxID}--> is set to expire on <!--{SiteDeleteDate}-->. If you have any questions or concerns, please contact your admin.";
            policy.SavePolicy();
            context.ExecuteQuery();

            // Refetch the edited Site Policy from the server
            policy = ProjectPolicy.GetCurrentlyAppliedProjectPolicyOnWeb(context, web);
            context.Load(policy,
                         p => p.Name,
                         p => p.Description,
                         p => p.EmailSubject,
                         p => p.EmailBody,
                         p => p.EmailBodyWithTeamMailbox);
            context.ExecuteQuery();

            // Display the new Site Policy properties and pause
            Console.WriteLine(String.Format("Policy Name is: {0}", policy.Name));
            Console.WriteLine(String.Format("Policy Description is: {0}", policy.Description));
            Console.WriteLine(String.Format("Policy E-mail Subject is NOW: {0}", policy.EmailSubject));
            Console.WriteLine(String.Format("Policy E-mail Body is NOW : {0}", policy.EmailBody));
            Console.WriteLine(String.Format("Policy E-mail Body (with Site Mailbox) is NOW: {0}", policy.EmailBodyWithTeamMailbox));
            Console.ReadLine();
        }
    }
}
2
  • Do I need build such console application and then Run it to change email content and format. Is there any other way like through powershell command etc ? Also how can I include say site owner , site name , url such information in the email body sent. Commented Nov 26, 2015 at 8:29
  • You can adapt it to powershell, I've done it before but don't have the code handy anymore. This is a wildcard and is replaced with your site URL, <!--{SiteUrl}-->, Site Name you could insert in, I don't believe you can alter the owners. Commented Nov 30, 2015 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.