///<summary> ///This is a function used to send mail to the required user/administrator ///</summary> private static void MailThisAlert(object Mdata) { MailingData mailingData = Mdata as MailingData; string smtpAddress = "smtp.gmail.com"; int portNumber = 587; bool enableSSL = true; string emailFrom = "*****@*****.**"; string password = "******"; string emailTo = null; foreach (User user in GlobalResources.Users) { if (string.Equals(user.UserName, mailingData.CompromisedUser)) { emailTo = user.Email_ID; } } string subject = "RBS Alert"; string message = "Your restrictions has been violated by " + GlobalResources.CurrentUser.UserName + " as given below : <br/><br/>"; string AlertNo = "No : " + mailingData.Alert.No + "<br/><br/>"; string AlertTime = "Time : " + mailingData.Alert.Time + "<br/><br/>"; string AlertDate = "Date : " + mailingData.Alert.Date + "<br/><br/>"; string AlertInformation = "Information : " + mailingData.Alert.Information + "<br/><br/>"; string ALertActivity = "Activity : " + mailingData.Alert.Activity + "<br/><br/>"; string AlertType = "Type : " + mailingData.Alert.Type + "<br/><br/>"; string body = message + AlertNo + AlertTime + AlertDate + AlertInformation + ALertActivity + AlertType; using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress(emailFrom); mail.To.Add(emailTo); mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.Credentials = new NetworkCredential(emailFrom, password); smtp.EnableSsl = enableSSL; smtp.Send(mail); } } }
public static void InitializeMailingSystem() { GlobalResources.SendMail += GlobalResources_SendMail; // To send mail Mdata = new MailingData(); }