Sending customized email from SharePoint Workflow

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

 SPFarm farm = workflowProperties.Site.WebApplication.Farm;
 SPIncomingEmailService emailService = (SPIncomingEmailService)farm.GetChild<SPIncomingEmailService>();
 string serverDisplayAddress = emailService.ServerDisplayAddress;
  
 SPList list = workflowProperties.List;
 SPAlertCollection alertCollection = workflowProperties.Web.Alerts;
 ArrayList aListUniqueUser = new ArrayList();
 foreach (SPAlert alert in alertCollection)
 {
     if (alert.AlertType == SPAlertType.List)
     {
         if (alert.List.ID == list.ID)
         {
             if (!aListUniqueUser.Contains(alert.User.Email))
                 aListUniqueUser.Add(alert.User.Email);
         }
     }
 }
 string toAddress = "";
 foreach (string s in aListUniqueUser)
     toAddress += s + ";";
  
 sendEmail1.From = workflowProperties.List.EmailAlias + "@" + serverDisplayAddress;
 sendEmail1.To = toAddress;
 sendEmail1.Subject = workflowProperties.Item["Subject"].ToString() + "-[" + workflowProperties.Item["ID"].ToString() + "]";
 sendEmail1.Body = workflowProperties.Item.Fields["Body"].GetFieldValueAsText(workflowProperties.Item["Body"]);