/// <summary> /// Sends emails to those emails, where each email contains those users email addresses. /// </summary> /// <param name="hashedList"></param> /// <param name="dataSource"></param> private void SendEmails(Dictionary <string, List <int> > hashedList, DataTable dataSource) { MailManager m = new MailManager(); List <int> updateKeys = new List <int>(); foreach (string emailAddress in hashedList.Keys) { XmlDocument xDoc = new XmlDocument(); xDoc.AppendChild(xDoc.CreateXmlDeclaration("1.0", System.Text.Encoding.UTF8.WebName, "yes")); XmlElement eForms = xDoc.CreateElement("eforms"); xDoc.AppendChild(eForms); List <int> emailPriKeys = hashedList[emailAddress]; updateKeys.AddRange(emailPriKeys); string toName = ""; string toAddress = emailAddress; foreach (int priKey in emailPriKeys) { DataRow record = dataSource.Select(SurgeryAppointment.SurgeryAppointmentId + " = " + priKey)[0]; toName = record[SurgeryAppointment.ApptCaseSurgeon].ToString(); XmlElement eFormNode = CreateEFromNode(xDoc, record); eForms.AppendChild(eFormNode); } // Prepare the message MailMessage message = new MailMessage(); message.From = m.AdminMailAddress; message.To.Add(new MailAddress(emailAddress, toName)); message.Subject = "Here are the surgeries for " + toName + " on " + SearchDateText; // Generate HTML output based on EForm XML XslTransform transformer = new XslTransform(); XsltArgumentList argList = new XsltArgumentList(); argList.AddParam("surgeonName", string.Empty, toName); argList.AddParam("surgeonEmail", string.Empty, emailAddress); argList.AddParam("surgeryDate", string.Empty, SearchDateText); argList.AddParam("urlBase", string.Empty, PageUtil.GetAbsoluteUrl(this.Page, "~/")); transformer.Load(Server.MapPath(XSLTPath)); System.IO.StringWriter messageWriter = new System.IO.StringWriter(); transformer.Transform(xDoc, argList, messageWriter); message.Body = messageWriter.ToString(); message.IsBodyHtml = true; m.SendEmail(message); } // Update Last Notification Date AppointmentDa da = new AppointmentDa(); da.UpdateLastNotificationDate(updateKeys, DateTime.Now); }