private static string FormatContactInfo(Family[] roster, Group group) { StringBuilder contactInfo = new StringBuilder(); foreach (string id in group.Members) { if (id == null) continue; var family = Array.Find(roster, f => f.FamilyId == id); Debug.Assert(family != null); contactInfo.AppendFormat("{0}, {1} and {2}", family.LastName, GetStringFor(family.FirstNames, 0), GetStringFor(family.FirstNames, 1)); contactInfo.AppendLine(); contactInfo.AppendFormat("\t{0}\t{1}", GetStringFor(family.EmailAddresses, 0), GetStringFor(family.PhoneNumbers, 0)); string email2 = GetStringFor(family.EmailAddresses, 1); string phone2 = GetStringFor(family.PhoneNumbers, 1); if (!String.IsNullOrWhiteSpace(email2)) { contactInfo.AppendLine(); contactInfo.AppendFormat("\t{0}\t{1}", email2, phone2); } contactInfo.AppendLine(); contactInfo.AppendLine(); } return contactInfo.ToString(); }
private static void AddEMailRecipients(Family[] roster, string[] memberIds, MailAddressCollection addresses) { foreach (string id in memberIds) { if (id == null) continue; var family = Array.Find(roster, f => f.FamilyId == id); Debug.Assert(family != null); foreach (string email in family.EmailAddresses) { if (String.IsNullOrEmpty(email)) continue; addresses.Add(new MailAddress(email)); } } }
private static void SendEmailToGroups(Family[] roster, Group[] generatedGroups) { foreach (Group g in generatedGroups) { using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress("*****@*****.**", "Kevin and Sarah Reynolds"); AddEMailRecipients(roster, g.Members, mail.To); //mail.CC.Add(new MailAddress("*****@*****.**", "Larry Rutledge")); //mail.CC.Add(new MailAddress("*****@*****.**", "Tina Rutledge")); mail.Subject = "Your Dinners for 6 Group"; mail.IsBodyHtml = false; // assign a random group member to initiate first contact. int n = new Random().Next(g.Members.Length); var initiatingFamily = Array.Find(roster, f => f.FamilyId == g.Members[n]); mail.Body = "Below is your dinners for 6 group for this quarter. To help get things started, one couple in each group has been chosen at random to initiate first contact. Try to meet three times this quarter. Please make an earnest effort to get together with your group--they will likely not meet without you!\n\nOne more thing: Please include the Rutledges in your group correspondence ([email protected]; [email protected]). They would like to crash some dinners for six groups--unless you're going to McDonald's.\n\n"; mail.Body += "Couple responsible for getting the ball rolling: " + initiatingFamily.LastName + "\n\n"; mail.Body += FormatContactInfo(roster, g); using (SmtpClient smtpClient = new SmtpClient("smtp.live.com", 587)) { smtpClient.UseDefaultCredentials = false; smtpClient.EnableSsl = true; smtpClient.Credentials = new NetworkCredential("*****@*****.**", "*Kevin2Olathe*"); smtpClient.Send(mail); } } } }
public GroupGenerator(Family[] roster, Exclusion[] exclusions, History history) { _roster = roster; _exclusions = exclusions; _history = history; }