A few days ago I had a problem with sending emails when a new task is added to a Sharepoint tasks list. I want to make a brief introduction for you to understand the context before going on with explaining the issue: we have a workflow that creates tasks in the default task list of a team collaboration site. The security requirement is to give read permissions to the user assigned to the task and also to a specific sharepoint group.
I decided to implement the security requirement as part of an event handler:
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
this.DisableEventFiring();
SPWeb web = properties.OpenWeb();
SPUser user = web.SiteUsers.GetByID(Convert.ToInt32(properties.AfterProperties["AssignedTo"]));
if (!properties.ListItem.HasUniqueRoleAssignments)
{
properties.ListItem.BreakRoleInheritance(false);
}
SPGroup group = properties.ListItem.Web.SiteGroups["My Group"];
SPRoleAssignment assignment1 = new SPRoleAssignment(group);
SPRoleDefinition roleDefinition = properties.ListItem.Web.RoleDefinitions["My Custom Permission Level"];
assignment.RoleDefinitionBindings.Add(roleDefinition);
properties.ListItem.RoleAssignments.Add(assignment1);
properties.ListItem.Update();
SPRoleAssignment assignment2 = new SPRoleAssignment(user.LoginName, user.Email, user.Name, string.Empty);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
properties.ListItem.RoleAssignments.Add(assignment2);
properties.ListItem.Update();
this.EnableEventFiring();
}
When testing I noticed that no email is sent after the workflow creates a new task and after our handler is called. What was very weird was that only the notification for the task creation hadn’t been sent. If you change the task the assigned person will receive the notification email.
I had to understand the mechanism that handles email notifications: the alerts Sharepoint collaboration feature. I found a few interesting things during my tests and “google research” and I want to share this information with you before going back to our issue.
The alerts are scoped to the site level and can be associated with lists, items or custom object. If you construct a site using a Team Collaboration site definition an alert will be created automatically and associated with the Tasks list. This happens because the E-Mail Notification option of the Tasks list is turned on (Tasks > Settings > Advanced Settings). If you select “No” the alert will be deleted.
In order to see the existing alerts (including their properties) of a Sharepoint site I use Sharepoint Manager 2007. This tool uses only the Sharepoint Object Model (OM) to display the Sharepoint information and offers a good opportunity to learn a lot of things about the OM capabilities.
The following snapshot presents the properties of the default Tasks list alert:
Worth to notice that our alert is the “System” alert, it is an immediate alert, it uses a dynamic recipient to get the email addresses, it has the List type and it is associated to the Tasks list.
Dynamic recipient means that the alert binds to the AssignedTo column of the Tasks list in order to retrieve the email addresses. So only the persons assigned to the task will be able to receive email notifications.
The immediate alerts can also be seen in the ImmedSubscriptions table of your content database.
The alert itself doesn’t send any emails. It just writes some entries in the content database (EventCache table) and, based on that records, someone else is there to send emails. The emails are effectively sent by the Immediate Alerts timer job (Central Administration > Operations > Timer Job Definitions). There is a job for each web application and by default it is set to execute every 5 minutes. Much information about troubleshooting abnormal behavior of the timer job can be found in this post.
The consequence observable from the end-user point of view is that there is some delay between the moment when the task is added/modified (alert logic writes in DB) and the moment when the email is received (timer job reads from DB and sends emails). In the worst case scenario you have to wait 5 minutes (by default) to see your new tasks or any changes of your existing tasks. If you want to modify the job timer scheduler you can do that with the following command:
stsadm.exe -o setproperty -pn job-immediate-alerts -pv “every 3 minutes between 0 and 59″ –url <WebAppUrl>
After I had understood all the mechanics of the notification process I looked for something wrong in my environment. Everything was fine so I started my research around Tasks list security. Here are the scenarios I tested and also my remarks:
1. I left the permissions inheritance unbroken. The list didn’t have any permission for the AssignedTo user. It was clear that trimming mechanism came into play and immediate alerts job doesn’t send any email. So ensure you assign the needed level of permissions to the AssignedTo user of the task item because it is the one that will receive the email notifications.
2. I broke the inheritance and added permissions only to the AssignedTo user. Surprise: that time was working! The task creation email notification was sent.
3. I moved the code that creates the permissions for the user above the one that creates permissions for the group. Surprise again! It was working.
4. I thought it might have something to do with the Update method call so I just commented out the first properties.ListItem.Update() statement in the original code of the event handler. This implementation worked as expected and it was our final solution.
It is obvious now where the problem was but it wasn’t at the implementation time of the event handler: In the original code the first Update creates the task item that is watched by the register alert. At this moment only the Sharepoint group has assigned permissions for the task item but not the AssignedTo user. Even if you add permissions to the AssignedTo user in the next Update it is too late because the alert considers the security at the moment when the task is created. This explains why the AssignedTo user starts to receive change notification even if he didn’t receive the task creation notification.


Super text, I will add this blog to my favorites.
Well , the view of the passage is totally correct ,your details is really reasonable and you nike air max shoes guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!
This site is so great that i will honor it with my comment
An update to a classic standby model, the new Puma Sky Hi+ ?he List?Replica Handbags Pack will change how you see super-hightop sneakers. Chunky, wide straps are usually reserved for ugg boots france the midfoot area, but that? what makes the Sky Hi+ different than its forebear. With a thick strap, ultra-high tongue and exaggerated midsole, you can immediately tell the Sky Hi+ apart from the OG Sky His. Check out more shots by clicking the jump below; pairs in blue or nike shoes france purple suede, red ripstop nylon, silvery faux reptile and crinkled black leather are all expected at German retailer
Agree with the views of the upper floors
That’s just the thing I need
Thanks for the info mate.
I just stumbled upon your blog. I love reading your posts.
Nice site, I just dugg this keep up the good work!. . . . . .
Good work ! Keep us posting, you are very good writer.
I was just browsing for relevant blog posts for my project research and I happened to stumble upon yours. Thanks for the useful information!
Nice site, I just dugg this keep up the good work!. . . . . .
google magic jack
upnp media server
I very much enjoyed your blog. Great posts! Please continue posting such excellent cotent.
Great post. I’m thinking that’s the best one…. Freelance SEO Specialist
I so enjoyed your site. Excellent content. Please keep posting such great cotent.
Longboards
Adding to my bookmarks thanks. A good quick read.
I enjoyed this. Where is your contact details though?
Really great informative blog post here and I just wanted to comment & thank you for posting this. I’ve bookmarked youi blog and I’ll be back to read more in the future my friend! Also nice colors on the layout, it’s really easy on the eyes.
Really amazing and informative blog post here. I just wanted to comment & thank you for posting this. I’ve bookmarked youi blog and I’ll be back to read more in the future my friend! Also nice colors on the layout, it’s really easy on the eyes.
Adding to my bookmarks thanks. Like your blog design too.
I tried to subscribe to your rss feed, but had a problem adding it to google reader. Could you please check this out.
Advantageously, the post is in reality the freshest topic on curing acne naturally. I concur with your conclusions and will thirstily look forward to your upcoming updates. Just saying thanks will not just be enough, for the phenomenal clarity in your writing. I will right away grab your rss feed to stay abreast of any updates.
Starcraft 2 Protoss are a humanoid race that communicates through telepathy as they have no mouths and sustain themselves through a form of photosynthesis.
Adding to my bookmarks thanks. Where is your contact details though?
Adding to my bookmarks thanks. A good quick read.
Great post, thanks. Where is your contact details though?
The main aspect of search engine marketing is keeping up with the constant changes in Bing and the people who are continously tweaking the algorythms. What I really want to learn are the sources that put out reliable seo data that is easy to understand.
Great Blog! I have a similar site, and get a lot of spam. Do you face such problems? Can you please recommend some steps I take to combat spam. Thanks.
Great post, thanks. Like your blog design too.
Hey I thought this was a very fascinating post thanks for writing it. You seem to be a very experienced writer. I recently made a post on different treatments for gynecomastia. Don’t be a stranger check out my blog tell me what you think? Thanks
I must say, I thought this was a pretty interesting read when it comes to this topic. Liked the material. . . . .
Wow this takes me back. Like your blog design too.
BKR problemen? Nu Geld lenen zonder BKR toetsing? Op zoek naar betrouwbare aanbieders? Wij vergelijken banken die u toch kunnen helpen aan een betrouwbare
anyone used the ultrahd flip mino hd? I’d like a feedback before purchasing one.
I wanted to say that it’s nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. Thanks for the answer.
I just book marked your blog on Digg and StumbleUpon.I enjoy reading your commentaries. Liam
This is second time that we are scanning anything about modifying websites with the method. It looks that you are an super expert blogger. Your method is an superb example of why I continue coming back to read your good quality content that is forever updated.
I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .
Hold yourself responsible for a higher standard than anyone else expects of you. Never excuse yourself. Thank You. . . .
Excellent read, I must say. You’ve researched the topic very well
I like the layout of your blog and Im going to do the same for mine. Do you have any tips? Please PM ME.
Interesting writing! Do you have any views that you would like to voice to explain the second part a bit more? cheers
Hi all, came across your site by chance in the early hours, but pleased that I have! As well as being full of sense and also easy to understand unlike lots that I come across. (My site, is a review of hypnotherapy downloads). I have been looking to see if I could work out what theme you were using, can somone give me an idea? The site I’ve made is a review site for hypnotherapy downloads. I have a similar layout on my site, which is related to hypnotherapy downloads, – I’ve found somehow and for whatever weird issue it appears to load swifter on yours though here you seem to have even more material. Have you been employing any widgets or plugins that speed it up? -Lastly, I appreciate such a great website and it’s a great inspiration for my modest review site of hypnotherapy downloads. I’m planning to improve my own website. I definitely will check back on this instructive blog often.
Hey, I searched for this blog on Bing and just wanted to say thanks for the excellent read. I would have to agree with it, thank you again!
Great post, thanks. Needed more pictures though.
Really informative blog post here my friend. I just wanted to comment & say keep up the quality work. I’ve bookmarked your blog just now and I’ll be back to read more in the future my friend! Also nice colors on the layout it goes well with the blog in my humble opinion
I enjoyed reading your interesting yet very informative insights. I am looking forward to reading more of your most recent articles and blogs.