public void SendMail(ProcessMonitor ProcessMonitor) { // Gmail Address from where you send the mail string fromAddress = ConfigurationManager.AppSettings["UserName"]; // any address where the email will be sending List<string> toAddress = GetToAdrress(ProcessMonitor.NotificationList); //Password of your mail address const string fromPassword = ""; // Passing the values and make a email formate to display string subject = ProcessMonitor.NotificationSubject; // smtp settings var smtp = new System.Net.Mail.SmtpClient(); { string ServerName = ConfigurationManager.AppSettings["EmailHost"].ToString(); smtp.Host = ServerName; smtp.UseDefaultCredentials = true; smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]); smtp.EnableSsl = false; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; //smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); } MailMessage mail = new MailMessage(); mail.Subject = subject; mail.From = new MailAddress(fromAddress); mail.Priority = MailPriority.High; mail.Body = subject; foreach (string address in toAddress) { mail.To.Add(address); } // Passing mail object to smtp object try { smtp.Send(mail); } catch (Exception e) { LogException logFile = new LogException(); logFile.Logging(e.Message+"\n\n"+e.StackTrace); } }
public List<ProcessMonitor> ReadingXml() { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; int i = 0; List<ProcessMonitor> processes = new List<ProcessMonitor>(); string path = Path.GetDirectoryName(Application.ExecutablePath)+"\\Process.xml"; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("ProcessMonitor"); for (i = 0; i <= xmlnode.Count - 1; i++) { ProcessMonitor process = new ProcessMonitor(); process.ProcessName = xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); process.NotificationList = xmlnode[i].ChildNodes.Item(1).InnerText.Trim(); process.TimeInterval = xmlnode[i].ChildNodes.Item(2).InnerText.Trim(); process.NotificationSubject = xmlnode[i].ChildNodes.Item(3).InnerText.Trim(); process.NotificationMail = xmlnode[i].ChildNodes.Item(4).InnerText.Trim(); processes.Add(process); } return processes; }
private bool CheckIfProcessMonitorRequired(ProcessMonitor pm) { bool needMonitoring = false; double lastInterval = (DateTime.UtcNow.Subtract(Convert.ToDateTime(pm.LastChecked))).TotalMinutes; if (lastInterval > int.Parse(pm.TimeInterval)) { needMonitoring = true; pm.LastChecked = DateTime.UtcNow; } return needMonitoring; }
private void NotifyUser(ProcessMonitor pm) { EmailService service = new EmailService(); service.SendMail(pm); }