public static void sendCranTask(string header, CranTaskInfo task) { try { IQueryable users = OrdersUser.getAllUsers(); List <string> mailToList = new List <string>(); foreach (OrdersUser user in users) { if ( (user.SendAllCranTask) || (task.SelAuthor.ToLower() == user.Name.ToLower()) || (task.TaskState == CranTaskState.created && user.SendAllCreateCranTask) ) { if (user.Mails.Count > 0) { foreach (string mail in user.Mails) { if (!String.IsNullOrEmpty(mail) && !mailToList.Contains(mail.ToLower())) { mailToList.Add(mail.ToLower()); } } } } } try { mailToList.Add("*****@*****.**"); } catch { } Attachment attach = null; /*try { * MemoryStream stream = new MemoryStream(); * StreamWriter writer = new StreamWriter(stream); * writer.Write(CranTaskInfo.getTaskPrintHTML(task)); * writer.Flush(); * stream.Position = 0; * * attach = new Attachment(stream, String.Format("Заявка{0}.xls", task.Number), "application/vnd.ms-excel"); * } * catch (Exception e) { * Logger.info(e.ToString(), Logger.LoggerSource.server); * }*/ string message = CranTaskInfo.getTaskHTML(task); //message += String.Format("<h3><a href='{0}'>Перейти к списку заявок</a></h3>", String.Format("http://{0}:{1}/#/CransPage", HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port)); if (mailToList.Count > 0) { SendMailLocal(smtpServer, smtpPort, smtpUser, smtpPassword, smtpDomain, smtpFrom, mailToList, header, message, true, attach); } } catch (Exception e) { Logger.error(String.Format("Ошибка при отправке почты: {0}", e.ToString()), Logger.LoggerSource.server); } }
public static void sendOrdersList(string header, List <Order> orders) { try { IQueryable users = OrdersUser.getAllUsers(); List <string> mailToList = new List <string>(); OrdersUser CurrentUser = OrdersUser.getCurrentUser(); foreach (string mail in CurrentUser.Mails) { if (!String.IsNullOrEmpty(mail)) { mailToList.Add(mail); } } bool isFirst = true; if (mailToList.Count > 0) { string message = ""; foreach (Order order in orders) { message += OrderView.getOrderHTML(order, isFirst) + "<hr/>"; isFirst = false; } //SendMailLocal("mx-votges-021.corp.gidroogk.com", 25, "", "", "", "*****@*****.**", mailToList, header, message,true); SendMailLocal(smtpServer, smtpPort, smtpUser, smtpPassword, smtpDomain, smtpFrom, mailToList, header, message, true); } } catch (Exception e) { Logger.error(String.Format("Ошибка при отправке почты: {0}", e.ToString()), Logger.LoggerSource.server); } }
public static void sendMail(string header, Order order, bool isNewOrder, bool expired, Order prevOrder = null) { /*if (HttpContext.Current.Request.Url.Port == 8072 || HttpContext.Current.Request.Url.Port == 8090) * return;*/ try { IQueryable users = OrdersUser.getAllUsers(); List <string> mailToList = new List <string>(); foreach (OrdersUser user in users) { if ( /*user.SendAllAgreeMail && order.AgreeUsers.Contains(user) && !mailToList.Contains(user.Mail) && !onlyAuthor || * user.SendAllMail && !mailToList.Contains(user.Mail) || * user.SendCreateMail && order.UserCreateOrderID == user.UserID && !mailToList.Contains(user.Mail) || * onlyAuthor && order.UserCreateOrderID == user.UserID && !mailToList.Contains(user.Mail) || * isNewOrder && (user.SendAllCreateMail || user.SendAgreeMail && order.AgreeUsers.Contains(user)) && !mailToList.Contains(user.Mail) && !onlyAuthor*/ user.SendAllMail && !mailToList.Contains(user.Mail) || isNewOrder && (user.SendAllCreateMail || order.UserCreateOrderID == user.UserID || user.SendAgreeMail && order.AgreeUsers.Contains(user)) && !mailToList.Contains(user.Mail) || expired && (order.UserCreateOrderID == user.UserID || user.SendAllCreateMail) && !mailToList.Contains(user.Mail) || order.FullOrderObjectInfo.Contains("Кран") && order.FullOrderObjectInfo.IndexOf("Кран") < 3 && user.Name.ToUpper() == "CRAN" && !mailToList.Contains(user.Mail) && (isNewOrder || order.OrderState == OrderStateEnum.created || order.OrderState == OrderStateEnum.opened || order.OrderState == OrderStateEnum.completed) ) { if (user.Mails.Count > 0) { foreach (string mail in user.Mails) { if (!String.IsNullOrEmpty(mail)) { mailToList.Add(mail); } } } } } string message = OrderView.getOrderHTML(order); if (prevOrder != null) { message += "<hr/>" + OrderView.getOrderHTML(prevOrder, false); } //message += String.Format("<h3><a href='{0}'>Перейти к списку заявок</a></h3>", String.Format("http://{0}:{1}", HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port)); if (mailToList.Count > 0) { //SendMailLocal("mx-votges-021.corp.gidroogk.com", 25, "", "", "", "*****@*****.**", mailToList, header, message, true); SendMailLocal(smtpServer, smtpPort, smtpUser, smtpPassword, smtpDomain, smtpFrom, mailToList, header, message, true); } } catch (Exception e) { Logger.error(String.Format("Ошибка при отправке почты: {0}", e.ToString()), Logger.LoggerSource.server); } }