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.


Hello,
Thank you for your blog post on this subject. It was great to confirm a couple of things I had also discovered. Have you every modified the standard new task assignment email verbiage ? If so where did you modify it and how ?
thanks
victor
706-577-3993
I was wondering the same thing a victor. We need to change the verbiage in the email message when the sharepoint workflow creates a task.
Great website , love the design. Seriously considering migrating to this blog platform now!
Interesting article i totally agree with the comments above. Keep writing
I really enjoy your site. Thank you for sharing!
I really enjoy your site. Thank you for sharing!
Thanks for the great post! You have a new fan.
i am quite often roaming all around the internet almost all of the afternoon thus I have a propensity to peruse quite a lot, which unfortunately is not always a good factor as a great number of the internet sites I look at are constructed of unproductive trash copied from different web pages a zillion times, however I gotta give you props this webpage is definitely not bad at all and includes some original information, for that reason kudos for smashing the trend of simply duplicating other folks’ blogs
People in the world get the home loans from different banks, because it’s simple and comfortable.
Thanks for posting. My dad would love your site!
Cool post! How much stuff did you have to look up in order to write this one? I can tell you put some work in.
Educational and entertaining. I’ve additional your internet log to my “reading substance. ” Progress me updated!. . . .
Hi there, I can see that your case is rather thoughtful as it talks about an assorted range of insightful data. In Any Case, was overcurious whether you would want to interchange web links with my web site, as I am looking forward to generate more web links to further enlarge and get better web exposure for my website. I don’t really mind you locating my links at the front page, just accepting this links on this respective page is good and adequate. Also, would you please reach me at my website if you are interested in swapping links, I would really like that. Thanks a lot and hopefully to get a reply from you shortly!
Thank you for such a fantastic blog. Where else could one get this kind of info written in such an incite full way? I have a presentation that I am just now working on, and I have been looking for such information.
By far the most concise and up to date information I found on this topic. Sure glad that I navigated to your page by accident. I’ll be subscribing to your feed so that I can get the latest updates. Appreciate all the information here
I came across your blog, i think your blog is interesting, keep us posting.
hey,just identified your web-site when i google something and wonder what hosting do you use for your wordpress,the speed is more faster than my website, i really need it.will back to check it out,thank you!
I obtain your website by bing. This is a great site along with image. I will certainly frequently revisit.
You post informative posts. Bookmarked !
I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful.
O widze masz podobne zainteresowania do moich, fajna strona, zajrze tu niedlugo
Ciekawy artykul, bede wpadal na twoja strone czesciej zapewne
Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.
I love tattoos and don’t for a second regret getting any of them, I’m currently getting a dragon tattoo down my right arm can’t wait to get it all done! as can only afford smallsessions at a time. My tattoo artist is very good and also extremly expensive but, he’s worth it! Great site btw
I adore tattoos and don’t for a minute regret getting any of them, I’m currently getting a koi tattoo done down my left arm can’t wait to get it all done! as can only afford smallsessions at anytime. My local tattoo artist is very good and also extremly expensive but, he’s worth it! btw could anyone point me in the right direction to get a original libra tattoo please.
I adore tattoos and don’t for a minute regret getting any of them, I’m currently getting a koi tattoo done down my left arm can’t wait to get it all done! as can only afford smallsessions at anytime. My local tattoo artist is very good and also extremly expensive but, he’s worth it! btw could anyone point me in the right direction to get a original libra tattoo please.
If any person wants to join world of warcraft ill Recruit u so we u joing can lv up faster or get cool mounts an even prizes:} Just hit me up
I simply wanted to say your website is one of the nicely laid out, most inspirational I have come across in quite a while. Thx!
I found a truly amazing WoW guide while looking for gold getting ideas on Youtube. I bought the guide and it kicks ass.
I feel you are too good to write Genius!Thanks for posting, maybe we can see more on this.
You’ve given me an amazing idea. Thanks for sharing this info with me.
Heya¡my very first comment on your site. ,I have been reading your blog for a while and thought I would completely pop in and drop a friendly note. . It is great stuff indeed. I also wanted to ask..is there a way to subscribe to your site via email?
You gave fantastic honest ideas here. I performed a research on the issue and discovered almost all peoples will agree with your Cartucce blog. How can I subscribe to RSS?
Nice job in this post! I found it very insightful. I’ve saved the link to your web site and I am certain that I’ll come back many more times in the future.
Had some difficulty viewing the site in Firefox on the Mac, but apart from that loved the site!
Very Interesting article. I already bookmarked this page. From where do you make your research for these articles?
Nice work on this post! I found it very insightful. I’ve saved the link to your web page and I’m positive that I’m going to return many more times in future.
posty interesujace, ja poprawil bym troche grafike i bylby idealny blog
Good! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?
Artykuly ciekawe, ja poprawil bym troche grafike i bylby idealny blog
The main reason of all of this are chem trails.
Intimately, the post is in reality the freshest topic on this registry related issue. I concur with your conclusions and will eagerly look forward to your forthcoming updates. Saying thanks will not just be enough, for the wonderful clarity in your writing. I will immediately grab your rss feed to stay abreast of any updates.
Intimately, the post is in reality the freshest topic on this registry related issue. I concur with your conclusions and will eagerly look forward to your forthcoming updates. Saying thanks will not just be enough, for the wonderful clarity in your writing. I will immediately grab your rss feed to stay abreast of any updates.
Of course, what a great site and informative posts, I will add backlink and bookmark this web site? Regards, Reader.
Supra Skytop royal Blue skate, Supra Skytop royal Blue skate
Supra Skytop royal Blue White, Supra Skytop royal Blue White
Supra Muska Skytop tuf Black, Supra Muska Skytop tuf Black
supra vaider mexico black red, supra vaider mexico black red
supra vaider navy blue grey, supra vaider navy blue grey
supra vaider purple patent, supra vaider purple patent
Great post! I started following your blog about a month ago and I like your honesty. Good example to emulate.
Good to become visiting your website once more, it’s got been months for me. Properly this write-up that i’ve been waited for so lengthy. I need to have this post to full my assignment inside college, and it’s got exact same topic together with your content. Thank you, good share.
Interesting post. I’ve saved this page to check back later.
Bookmarked your site. Thank you for sharing. Definitely worth the time away from my classwork.