private void SendMail(BenQGuru.eMES.Domain.Alert.Alert alert) { BenQGuru.eMES.Web.Helper.ESmtpMail mail = this.GetNewMail(); //收件人 BenQGuru.eMES.BaseSetting.UserFacade userfacade = new BenQGuru.eMES.BaseSetting.UserFacade(DataProvider); int recipientCount = 0; foreach (ListItem li in this.lstUser.Items) { if (li.Value != null && li.Value != string.Empty) { BenQGuru.eMES.Domain.BaseSetting.User user = userfacade.GetUser(li.Value) as BenQGuru.eMES.Domain.BaseSetting.User; if (user != null && user.UserEmail != null && user.UserEmail != string.Empty && user.UserEmail.IndexOf("@") != -1) { mail.AddRecipient(user.UserName, user.UserEmail); recipientCount++; } } } if (recipientCount > 0) { mail.Body = alert.AlertMsg; if (!mail.Send()) { BenQGuru.eMES.Common.ExceptionManager.Raise(this.GetType(), mail.ErrorMessage); } } }
private ESmtpMail GetNewMail() { if (this._mail == null) { _mail = new ESmtpMail(); string fileFullPath = BenQGuru.eMES.Common.Config.ConfigSection.Current.ConfigFileFullPath(); XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(fileFullPath); XmlNode node = doc.SelectSingleNode("//EmailConfiguration/SMTPServer"); if (node != null) { _mail.MailDomain = node.InnerText; } node = doc.SelectSingleNode("//EmailConfiguration/UserName"); if (node != null) { _mail.MailServerUserName = node.InnerText; } node = doc.SelectSingleNode("//EmailConfiguration/Password"); if (node != null) { _mail.MailServerPassWord = node.InnerText; } node = doc.SelectSingleNode("//EmailConfiguration/FromEmail"); if (node != null) { _mail.From = node.InnerText; } node = doc.SelectSingleNode("//EmailConfiguration/FromName"); if (node != null) { _mail.FromName = node.InnerText; } node = doc.SelectSingleNode("//EmailConfiguration/Subject"); if (node != null) { _mail.Subject = node.InnerText; } _mail.Html = false; } return(this._mail); }
public static void SendMail(string currentUserMail, object[] users, MailMessage mailMessage) { BenQGuru.eMES.Web.Helper.ESmtpMail smtp = new BenQGuru.eMES.Web.Helper.ESmtpMail(); for (int i = 0; i < users.Length; i++) { string eMail = (users[i] as User).UserEmail; if (eMail.Trim().Length == 0) { continue; } smtp.AddRecipient(eMail); } smtp.MailDomain = System.Configuration.ConfigurationSettings.AppSettings["MailDomain"].ToString(); smtp.MailServerUserName = System.Configuration.ConfigurationSettings.AppSettings["MailServerUserName"].ToString(); smtp.MailServerPassWord = CommonFunction.DESDeCrypt(System.Configuration.ConfigurationSettings.AppSettings["MailServerPassWord"].ToString()); smtp.Subject = mailMessage.Subject; smtp.Body = mailMessage.Body; smtp.From = currentUserMail; smtp.FromName = "MESϵͳ"; smtp.Html = true; smtp.Send(); }