I recently got a requirement from a customer asking for a solution that will send a customized email to the people. These were the requirements
1. The 'From address' of the email should be title of discussion list.
2. The 'To address' of the email should be to all the subscribers of that list (Alert configuration)
3. The 'Email Subject' should be the subject of topic + Subject ID.
4. The Body should have the actual content of the Discussion list.
Using SharePoint Designer, creating workflow with these functionalities was not possible. So, ultimately i had to end up writing custom workflow using visual studio. I decided to use SendEmail Activity thats already available Out of the box. In the MethodInvoking of SendEmail activity, I had to put down all logic to get this requirements done.
Getting the subject and body of the email was no big deal. The From address was a bit tricky as I had to write some code to get email alias of the list and append it with the server display address from IncomingEmailService.
The real challenge was in getting the ‘To Address’. The To address should contain all the users who were actually subscribed for that list Alert. So how will I get the list of users who are subscribed for that list? There was no direct API support available wherein we could get all the subscribed users from a given list. No direct mapping existed between the subscribed users and the list.
So here is the clue. Every time a new user is subscribed for a list, a new alert gets created!! I had to loop through the complete alert collection of the web, get into the correct list and then get user email from that alert and make sure that the final collection had only unique users.
The complete code snippet : SendEmail Method Invoking