public string Send(string value) { EmailToSend emailToSend = JsonConvert.DeserializeObject <EmailToSend>(value); MySqlIdentityDbContext db = new MySqlIdentityDbContext(); var files = Request.Files; string result = ""; if (User == null || !User.Identity.IsAuthenticated) { return(""); } var claims = UserManager.GetClaims(User.Identity.GetUserId()); EmailFactory factory = new EmailFactory(claims); int j = 0; foreach (string sendTo in emailToSend.SendTo) { try { var message = factory.GetTemplate(emailToSend.Template, sendTo); Object obj = new Object(); /*/ * if (emailToSend.Type == "candidat") * { * obj = db.Candidats.Where(a => a.Email == sendTo).FirstOrDefault(); * } * else if (emailToSend.Type == "customer") * { * obj = db.Customers.Where(a => a.Email == sendTo).FirstOrDefault(); * } * else if (emailToSend.Type == "linkedin") * { * obj = db.ContactLinkedins.Where(a => a.Email == sendTo).FirstOrDefault(); * } * else * { * result = result + "<tr><td>" + sendTo + "</td><td><b> Type d'objet non spécifié </b> </td></tr>"; * continue; * }/*/ // ajout des pièces jointe si elles existent if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { message.Attachments.Add(new System.Net.Mail.Attachment(files[i].InputStream, files[i].FileName)); } } // Envoyer l'email à l'administrateur et à l'utilisateur qui envoie if (j == 0) { try { message.To.Clear(); message.To.Add(new MailAddress(User.Identity.Name)); factory.Send(factory.ReplaceVariableInTemplate(message, obj)); logger.Info(" Email copy sent to : " + User.Identity.Name); if (ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo"] != User.Identity.Name) { message.To.Clear(); message.To.Add(new MailAddress(ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo"])); factory.Send(factory.ReplaceVariableInTemplate(message, obj)); logger.Info(" Email copy sent to : " + ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo"]); } if (ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo2"] != User.Identity.Name) { message.To.Clear(); message.To.Add(new MailAddress(ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo2"])); factory.Send(factory.ReplaceVariableInTemplate(message, obj)); logger.Info(" Email copy sent to : " + ConfigurationManager.AppSettings["SmtpServer:AllEmailCciTo2"]); } } catch (Exception ex) { logger.Error(" Error in sending Cci email - " + ex.Message); } message.To.Clear(); message.To.Add(new MailAddress(sendTo)); } factory.Send(factory.ReplaceVariableInTemplate(message, obj)); result = result + "<tr><td>" + sendTo + "</td><td><b> Envoyé </b> </td></tr>"; logger.Info(" Email copy sent to : " + sendTo); j++; } catch (Exception ex) { result = result + "<tr><td>" + sendTo + "</td><td><b> Non envoyé</b> </td></tr>"; logger.Error(ex.Message); } } return(result); }