public static Boolean SendMail(String receiver, String message) { if (_mailer == null) { lock (_lock) { if (_mailer == null) { _mailer = MailLoadConfig.Load(); } } } //Prepare Message MailMessage mail = new MailMessage(); mail.From = new MailAddress(_mailer.smtpFromEmail, _fromName); mail.To.Add(receiver); mail.Subject = "Registration Confirmation Email"; mail.Body = message; //send the message SmtpClient smtp = new SmtpClient(_mailer.SmtpServer); smtp.Port = _mailer.SmtpPort; smtp.Credentials = new NetworkCredential(_mailer.SmtpUserName, _mailer.SmtpPassWord); smtp.EnableSsl = true; smtp.Send(mail); mail.Dispose(); smtp.Dispose(); return true; }
public static MailModel Load() { Environment.CurrentDirectory = HttpContext.Current.Server.MapPath("/"); XmlTextReader xmlFile = new XmlTextReader(_filePath); xmlFile.Read(); MailModel mail = new MailModel(); while (xmlFile.Read()) { xmlFile.MoveToElement(); if (xmlFile.NodeType == XmlNodeType.Element && xmlFile.Name.Equals("mail")) { mail.SmtpPassWord = xmlFile.GetAttribute("smtpPassword").Trim(); mail.SmtpPort = Int16.Parse(xmlFile.GetAttribute("smtpPort")); mail.SmtpServer = xmlFile.GetAttribute("smtpServer").Trim(); mail.SmtpUserName = xmlFile.GetAttribute("smtpUserName").Trim(); mail.smtpFromEmail = xmlFile.GetAttribute("smtpFromEmail").Trim(); } } xmlFile.Close(); return mail; }