Is there a way to determine if a email is a reply/response using ews c#?

戏子无情 提交于 2019-12-05 17:28:38

问题


I am writing a support system and this is my first time using EWS. Thus far I have been quite successful with it. I can extract the info I need. Send emaisl and everything is working great. I do have one small headache. Is there a way to tell if an email is in fact a reply ? The basic idea of the app is someone sends an email. We reply and give them a reference number. This is done and working great. Now if they reply to this same address, we need to log it a bit different in our database. thus I need some magical way to tell if the email is a reply. Thus far I am stuck.

Any suggestions will be greatly appreciated as I am new in the programming industry and thus far googling turned up nothing useful. I include a section of code here

 FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, view);

        foreach (Item myItem in findResults.Items.Where(i => i is EmailMessage))
        {
            var mailItem = myItem as EmailMessage;
            if (!mailItem.IsRead)
            {
                // load primary properties and get a text body type
                mailItem.Load(propertySet);
                // Update the item to isRead in email
                mailItem.IsRead = true;
                mailItem.Update(ConflictResolutionMode.AutoResolve);

                //Check if it is a reply and mark the msg as such

                // add message to list
                SupportEmailMessage msg = new SupportEmailMessage();
                msg.Subject = mailItem.Subject;
                msg.MessageBody = mailItem.Body.Text;
                msg.DateSent = mailItem.DateTimeSent;
                msg.Sender = mailItem.Sender.Address;
                toReturnList.Add(msg);
            }

        }

回答1:


InReplyTo is a string value that contains the identifier of the item to which this message is a reply. If it's null, then the message is not a reply.

var mailItem = myItem as EmailMessage;
if (mailItem.InReplyTo != null)
{
   // this is a reply message
   .
   .
   .
}

Further info: MSDN InReplyTo




回答2:


Ok. So from the Comments. It seems that There is not really a definitive way. People's comments helped me get this answer and to close this thread. I will reword and post it here. So first. Thanks for all your answers.

The most simple way is to include a good reference number in your subject. Such as "Supp-1234"

Now in code we can check for that reference number in the heading. If it is there. It is most likely a response. Checking for RE is also an option, but somewhat less effective. The bummer is that clients can remove the reference number/RE from the subject heading. For those guys. Poor you, your issue won't get logged. or you know. do whatever. :)

Thanks again to all responses. You guys really helped me a lot !



来源:https://stackoverflow.com/questions/17854750/is-there-a-way-to-determine-if-a-email-is-a-reply-response-using-ews-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!