How to send an email when a SharePoint site or web is deleted
For various governance reasons you may want to email the site owner when a SharePoint site is deleted. A list of the possible reasons could be :
- The site was deleted in error and the earlier you notify the owners – the better. (it can be restored if you have a back-up).
- Maybe you have an automated governance job that deletes unused sites after so many days. Once these sites are deleted it’d be good to know (for reason 1).
- Maybe there is an auditing requirement to track deletions?
Either way – it’s pretty easy to get this all setup by using a site-scoped hidden feature as follows:
What does the Feature do?
The feature will email the following people as the site collection or web is deleted.
- Site Collection Administrator + Secondary Contact Admin
- The Web Administrators / Owners
- Any users in the associated owners group of the site
Please note, to get this to work, the SMTP settings must be configured from Central Admin and the users (above) must have an email address in SharePoint.
To get started – download this WSP and save it to a directory on one of your application servers. (Also, do this out of our hours – as it will recycle the app pools on your web apps).
On the app server, load the SharePoint 2010 Management Shell and deploy the WSP into the farm store as follows :
Now load Central Admin and navigate to Farm Solutions screen. Once you have found ‘Sitedeletealerter.wsp’ – click on it and the click ‘Deploy Solution’… Wait a while…
Now, you need to activate the feature on any site collections where you wished to be emailed about sites being deleted. As follows :
If you want to customise the standard email message that gets sent out – add an ‘AppSetting’ key / value pair called (‘SiteDeletedEmailMessage‘) inside the web.config of the web application containing your site collection(s). This is optional though.
Hope you find this helpful. As with all freebies – use at your own risk 😉