如何在列表中添加字符串“matchingmessage”< item> [英] How to add a string “matchingmessage” into the list<item>

查看:132
本文介绍了如何在列表中添加字符串“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();

    }

}





我是什么已尝试:





What I have tried:

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

推荐答案

试试这个



try this

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",};

foreach (Item item in email.EmailList)
{
    string matchingMessage = pattern.FirstOrDefault(k => item.Body.Contains(k));
    dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.Body, matchingMessage);

}
GridView1.DataSource = dt;   // have moved this outside, else it will called again and again
GridView1.DataBind();         // which will result in stack over flow exception when huge records


这篇关于如何在列表中添加字符串“matchingmessage”&lt; item&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆