public static void SendEmailsNotifications(String subject, String machineName, String unityServer, float percentDisk) { String[] recipientList = ConfigurationManager.AppSettings["RecipientList"].Split(';'); String sender = ConfigurationManager.AppSettings["Sender"]; String nameSender = ConfigurationManager.AppSettings["NameSender"]; String password = ConfigurationManager.AppSettings["Password"]; String server = ConfigurationManager.AppSettings["Server"]; int port = int.Parse(ConfigurationManager.AppSettings["ServerPort"]); String mailTemplateHTMLNotify = ConfigurationManager.AppSettings["MailTemplateHTMLNotify"]; String template = RecuperTemplateHTML(mailTemplateHTMLNotify) .Replace("#PERCENTUAL#", $"{Math.Round(percentDisk, 2)}%") .Replace("#UNIDADE#", unityServer) .Replace("#SERVIDOR#", unityServer); if (recipientList != null && recipientList.Length > 0) { foreach (String recipient in recipientList) { try { if (!String.IsNullOrEmpty(recipient)) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(sender, nameSender); mail.To.Add(new MailAddress(recipient)); mail.Subject = subject; mail.Body = template; mail.IsBodyHtml = true; mail.Priority = MailPriority.High; using (var smtp = new SmtpClient(server, port)) { smtp.Timeout = 100000; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.EnableSsl = false; smtp.Credentials = new NetworkCredential(sender, password); smtp.Send(mail); } } } catch (Exception e) { LogGenerators.CreateLogErrorsCleaner(e.Message); } } } }
/// <summary> /// Method responsible for performing bytes to gigabytes conversion /// </summary> /// <param name="totalBytes">A value greater than or equal to 0, in bytes, must be entered.</param> /// <returns>Returns a value greater than or equal to 0 of type double</returns> public static double ConvertByteInGiga(double totalBytes) { double result = 0; double oneGigaInByte = 1073741824; // VALUE IN BYTES AND EQUIVALENT TO 1 GB try { if (totalBytes < 0) { throw new Exception("O valor em bytes não pode ser negativo."); } result = totalBytes / oneGigaInByte; } catch (Exception e) { LogGenerators.CreateLogErrorsCleaner(e.Message); } return(result); }