11

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);
            }

        }
KapteinMarshall
  • 490
  • 6
  • 20
  • 1
    you could do `msg.Subject.Contains("RE:")`.. sorry can't be of help +1 though – Sayse Jul 25 '13 at 10:00
  • Actually that is a good idea... Why didn't I think of that... Probably sleep deprivation. in theory I can try and run with this. hopefully work some magic... – KapteinMarshall Jul 25 '13 at 10:05
  • Haha I was joking as its got obvious limitations. if your looking for direct replies you can do `StartsWith("RE:")` i guess but I'm sure theres a better way if it is possible – Sayse Jul 25 '13 at 10:07
  • 1
    When I handle out and In emails using EWS I use keywords in the subject to identify what needs to be done. When EWS sends out, I may have INCIDENT ID1234 etc. When a message comes in, I check for keywords and act. no keywords means it is new. The downside is if people mess with the subject line. The SMTP protocol doesn't have anything saying if it is a reply or new message. One thing that might be possible is insert custom values into the message header http://stackoverflow.com/questions/17034222/do-email-clients-all-return-custom-headers-on-email-replies – Lotok Jul 25 '13 at 10:12
  • There probably is some weird way of doing it that I am missing. But right now its my lunch time. and I need coffee. After that I will struggle and google some more. – KapteinMarshall Jul 25 '13 at 10:12
  • Yes. I had the same idea of using a reference number. And yes clients will very likely mess around with the subject and delete the referenced text... ulg... clients. Thank you for your help guys. This is really helpful. – KapteinMarshall Jul 25 '13 at 10:16
  • 1
    Microsoft Dynamics CRM is designed for servicing, is very powerful and allows you to not reinvent the wheel. Trial is available for free http://www.microsoft.com/en-us/dynamics/crm-free-trial-overview.aspx. BTW I hate the thing ... but it gets the job done. It tracks emails too ! – Alex Jul 25 '13 at 12:46
  • I took a quick look at it. CRM looks really cool. I might try to convince my boss to use it. He however does not like buying licenses. He avoids them wherever possible. – KapteinMarshall Jul 25 '13 at 13:37
  • 2
    Added a reference to rfc-822 and `In-Reply-To:` field to the referenced question. – Victor Sergienko Jul 29 '13 at 10:29
  • @VictorSergienko I saw your answer on the other thread earlier. Nice 1 – Lotok Jul 29 '13 at 12:12

2 Answers2

7

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

jim31415
  • 8,588
  • 6
  • 43
  • 64
1

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 !

KapteinMarshall
  • 490
  • 6
  • 20