Как добавить строку “matchingmessage” в список<item>
how to add the string "matchingMessage" to the List<Item>? this is the only way that i think in order to display the result on the gridview. since the string matchMessage is not part on the list for now im using the email.matchingMessagePublic that is a public string that i declare on my class and the result on the gridview is only the same on the first result and here's my code
<pre>private bool DisplayErrorEmails(ExchangeService service) { try { FindItemsResults<Item> findResults; DateTime TwoDays = DateTime.Today.AddDays(-2); //Search for the Undelivered Email SearchFilter.SearchFilterCollection compoundFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.NDR")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.DR")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.DELAYED")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.IPNRN")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.IPNNRN")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.SMIME.NDR")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.SMIME.DR")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.NoteSMIME.MULTIPARTSIGNED.NDR")); compoundFilter.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "REPORT.IPM.Note.SMIME.MULTIPARTSIGNED.DR")); //Displays the result ItemView view = new ItemView(100); do { findResults = service.FindItems(WellKnownFolderName.Inbox, compoundFilter, view); foreach (Item item in findResults.Items) { if (findResults.ToString() != "") { EmailList.Add(item); item.Load(); string Sender = item.DisplayTo; string Subject = item.Subject; string DateCreated = item.DateTimeCreated.ToString(); //Display the EmailBody PropertySet itemProperty = new PropertySet(); itemProperty.RequestedBodyType = BodyType.Text; itemProperty.Add(ItemSchema.Body); PropertySet FindItemPropertySet = new PropertySet(BasePropertySet.IdOnly); view.PropertySet = FindItemPropertySet; PropertySet GetItemsPropertySet = new PropertySet(BasePropertySet.FirstClassProperties); GetItemsPropertySet.RequestedBodyType = BodyType.Text; if (findResults.Items.Count > 0) { service.LoadPropertiesForItems(findResults.Items, GetItemsPropertySet); foreach (Item Item in findResults.Items) { var EmailBody = Item.Body.Text; var pattern = new[] { "Remote Server returned '554 5.4.4 SMTPSEND.DNS.NonExistentDomain; nonexistent domain", "Either there are no alternate hosts, or delivery failed to all alternate hosts", "Remote Server returned '550 No Such User Here", "5.2.3 smtp;550 5.2.3 RESOLVER.RST.SendSizeLimit.Org; message too large for this organization", "5.1.10 smtp;550 5.1.10 RESOLVER.ADR.RecipientNotFound; Recipient user@contoso.com not found by SMTP address lookup", "Remote Server returned '550 4.4.7 QUEUE.Expired; message expired'", "Remote host said: 550-5.1.1 The email account that you tried to reach does not exist",}; string matchingMessage = String.Empty; var found = pattern.Any(m => { var match = EmailBody.Contains(m); if (match) matchingMessage = m; return match; }); matchingMessagePublic = matchingMessage; Console.WriteLine("Subject" + item.Subject); Console.WriteLine("Error::::" + matchingMessage); } } } } if (findResults.NextPageOffset != null) { view.Offset = (int)findResults.NextPageOffset; } } while (findResults.MoreAvailable); Status = "list of undelivered email."; return true; } catch (Exception ex) { Status = "Error: " + ex.Message; return false; } } and here's my code to display to the gridview <pre lang="c#">public void LoadResult() { EmailMethods email = new EmailMethods(); email.EmailServer = "https://SampleExchange.asmx"; email.AccountName = ConfigurationManager.AppSettings["Account"]; email.Password = ConfigurationManager.AppSettings["Secret"]; email.Domain = ConfigurationManager.AppSettings["Domain"]; email.GetEmails(); DataTable dt = new DataTable(); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("Sender", typeof(string)); dt.Columns.Add("DateCreated", typeof(string)); dt.Columns.Add("EmailHeader", typeof(string)); dt.Columns.Add("ErrorTwo", typeof(string)); foreach (Item item in email.EmailList) { dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.Body, email.matchingMessagePublic); GridView1.DataSource = dt; GridView1.DataBind(); } }
Что я уже пробовал:
on the email.matchingMessagePublic it display the first result and it fill the grid as a same result on the first one. if maybe i add the matchMessage to the item i think it will display the result correctly. Can anyone help me with my code please
ZurdoDev
Я понятия не имею, о чем ты просишь.
Member 13427032
могу ли я добавить sting matchingMessage в список "элемент"? потому что мой на то
ДТ.Строк.Добавить(элемент.Предмет, предмет.DisplayTo, пункт.DateTimeCreated, item.Тело, электронная почта.matchingMessagePublic);
чтобы отобразить результат в gridview на email.matchingMessagePublic, он отображает только одну и ту же запись, поэтому я попытался добавить matchingMessage в список "элемент", чтобы я мог отобразить правильный результат на данный момент я объявляю публичную строку matchingMessagePublic классу emailMethods. Cna вы поможете мне с моим кодом пожалуйста