static void Main(string[] args) { try{ // Starting with ClientContext, the constructor requires a URL to the server running SharePoint. static string FromGlob = "account@secondserver.ru"; // От кого отправляются письма(Заголовок писем) ClientContext context = new ClientContext("https://yoursuperserver.com"); context.Credentials = new System.Net.NetworkCredential("login", "passsword"); Guid GuidList = new Guid("{97945C4C-468A-4DF7-8941-3A8AF75C3F5C}"); //list GUID List lst = context.Web.Lists.GetById(GuidList); CamlQuery query = CamlQuery.CreateAllItemsQuery(); ListItemCollection itemsCollection = lst.GetItems(query); context.Load(itemsCollection); context.ExecuteQuery(); if (itemsCollection.Count != 0) {SendMail(FromGlob, sendToStandard, lst.name, itemsCollection.Count)} } catch (Exception ex) {Console.WriteLine("Big error\n {0}", ex.message);} } static void SendMail(string From, List<string> To, string Subject, string Body) { try { SmtpClient Smtp = new SmtpClient("yourmailserver.ru", 25); MailMessage Message = new MailMessage(); Message.From = new MailAddress(From); foreach (string manymail in To) // Кому { if (manymail.Contains('@')) {Message.To.Add(new MailAddress(manymail));} } Message.Subject = Subject; Message.Body = Body; Message.IsBodyHtml = true; Smtp.Send(Message);//отправка Message.Dispose(); } catch { Console.WriteLine("\n ### ERROR SEND MAIL 545: Trouble with send email Не смог отправить письма ... :{0} \n", To); } } |