using System; using System.Collections.Generic; using System.Net; using System.Net.Mail; using System.Text; using Model; using classes; /* Mail admins for problem payments ie users with ADMIN Role */ namespace PMF.Services { public static class Mailer { public static void SendEmail(List problemInfridgments, List admins) { //use the problemInfridgments and send emails to the admins StringBuilder sb = new StringBuilder(); sb.AppendLine("The Cronjob could not complete the following payments: "); foreach (var problemInfridgment in problemInfridgments) { sb.AppendLine("infringementID: " + problemInfridgment.InfringementID.ToString() + " NoticeNumber: " + problemInfridgment.NoticeNumber); } try { var smtpUser = SecretsManager.GetSesUser(); SmtpClient client = new SmtpClient() { Host = Constants.TMT_MAIL_HOST, Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential() { UserName = smtpUser.SMTP_Username, Password = smtpUser.SMTP_Password } }; MailAddress from = new MailAddress(Constants.TMT_MAIL, "PMF"); MailAddress to = new MailAddress("lloyd@overdrive.co.za"); //pmf admin email remove this if there is no primary email MailMessage message = new MailMessage(); message.From = from; message.To.Add(to); foreach (var adminEmail in admins) { message.CC.Add(new MailAddress(adminEmail)); } message.Subject = "PMF Error Payments"; message.Body = sb.ToString(); client.Send(message); } catch (Exception ex) { throw ex; } } } }