The full potential of Project Server is realized only when a powerful workflow solution is deployed along with it. One of the best workflow solutions is Solution Starters Dynamic Workflow (and it is free), which I mentioned in on of my previous posts.
Dynamic Workflow is great solution, but, it has many faults as well. One of them are email notifications to users who have workflow tasks assigned to them (approvers).
When project is send to approval, all tasks for all users are stored in SharePoint list called Project Server Workflow Tasks, and in that moment email notification is send to users who are approvers for that task.
This how this email looks like:
The problem is in its subject:
Project Server Workflow Tasks - Approval required for project: '... has been
assigned to you
In subject (or anywhere else in email) user can not see the name of the project, so user does not know what project he must approve/reject.
I have searched for the solution of this problem, but without success. These notifications are SharePoint generated emails, and subject of the email and the body are generated from series of XML definitions from SharePoint XML files (file is called alertemplates.xml and it is located in
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML
But, modifying this XML file is not recommendable, because all list on entire farm are using it, and it is also complicated to find what you need to change in order to get the desired results. I my next post, I will describe how to make your custom alert template XML file.
So, I've come up with a different solution. Solution is to turn off email notifications for this SharePoint list and to build a custom event receiver for that list which will send its own notifications with content that you desire:
1. Go to SharePoint list "Project Server Workflow Tasks":
Site Actions --> Site Settings --> Site libraries and lists (in Site Administration) --> Customize Project Server Workflow Tasks
2. Click on Advanced settings in section General Settings.
3. In section E-mail Notification, select option "No" for Send e-mail when ownership is assigned option.
4. Now it is time to open Visual Studio 2010 and build your event handler.
NOTE: Building an event handler for this particular list is not straight forward, but it can be found on blogs, so I will not go in detail here. If someone needs help with this part, leave a comment, and will try to help.
5. After the event handler has been made, System.Net.Mail library can be used for sending mail form code. Created new class and create following class in it. In it, you can read task title, owner of the task, approver, etc from SharePoint list. Here is the code:
class ProjectWorkflowEvent: SPItemEventReceiver
public override void ItemAdded(SPItemEventProperties properties)
//reading title value from Project Server Workflow Tasks list
string _title = properties.ListItem["Title"].ToString();
string _decision = properties.ListItem["Outcome"].ToString();
SPFieldLookupValue _assignedTo = new SPFieldLookupValue(properties.ListItem["Assigned To"].ToString());
string _assignedName = _assignedTo.LookupValue;
SPSite oSiteCollection = new SPSite(properties.WebUrl);
string _userMail = "";
using (SPWeb oWebSite = oSiteCollection.OpenWeb())
//read user email address
SPUser oUser = oWebSite.EnsureUser(_assignedName);
_userMail = oUser.Email;
string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
string smtpFrom = SPAdministrationWebApplication.Local.OutboundMailSenderAddress;
//Create the mail message and supply it with from and to info
MailMessage mailMessage = new MailMessage(firstname.lastname@example.org, email@example.com);
//Set the subject and body of the message
mailMessage.Subject = "Approval
required for project: '" + _title + "' has been assigned to you";
mailMessage.Body = "My custom body";
//Create the SMTP client object and send the message
SmtpClient smtpClient = new SmtpClient(smtpServer);
Now, your email can look something like this (or what ever you like):