none
2010 EWS 2.0 C# Windows 7: "Data is Corrupt" error, but only when forwarding messages from a certain user RRS feed

  • Question

  • I have an application that is basically a mailing list manager. New messages are sent to an Exchange mailbox, from outside of our organization. Periodically the application runs, scans the mailbox for new messages, and forwards them to the appropriate users. For the most part this works fine, but messages that come from a specific outside user cause a "Data is Corrupt" message.

    I have tried re-creating the messages that cause problems, both using Outlook and using a Gmail account. In both instances, the message went through the system with no problems. But this vendor is doing something that is causing me grief.

    I've included some sample code below. What I would really like are tips for debugging these kinds of problems. It seems to me that "Data is Corrupt" is sort of a generic error.

    private void ForwardMessage(EmailMessage msg, List<String> recipients, String replyTo)

         ResponseMessage stepOne;
         EmailMessage stepTwo;
         Folder drafts;
         ConversationId cid;

         /*
          * This is a little screwy.
          * EmailMessage.CreateForward() is really useful, because it preserves
          * attachments. But it mangles the message body and subject, so I have reset those.
          * And it doesn't support setting the Reply To, so I have to do this
          * in two steps: create the forward, save to Drafts, then get the
          * message in the Drafts forward, and set the Reply To.
          */

         cid = msg.ConversationId;

         stepOne = msg.CreateForward();
         stepOne.Body = msg.Body;
         stepOne.Subject = msg.Subject;
         foreach (String s in recipients)
         {
              stepOne.BccRecipients.Add(s);
         }
         stepOne.Save(WellKnownFolderName.Drafts);

         /*
          * There is a chance, though small, that another process
          * could create a draft message in response to the message
          * I'm in the process of forwarding. But it is unlikely,
          * so I'm going to live with this. Extended Properties would
          * be the safer way to do this, but I couldn't get them
          * to make the trip.
          */

         stepTwo = null;
         drafts = Folder.Bind(msg.Service, WellKnownFolderName.Drafts);
         foreach (EmailMessage em in drafts.FindItems(new ItemView(100)))
         {
              if (em.ConversationId.Equals(cid))
              {
                   stepTwo = em;
              }
         }

         if (stepTwo != null)
         {
              stepTwo.ReplyTo.Add(replyTo);
              // This next line is where the "Data is Corrupt" error keeps happening
              stepTwo.SendAndSaveCopy();
         }
    }

    Monday, June 9, 2014 11:13 PM

All replies

  • The place to start with Debugging would be to enable tracing and look at requests and responses your getting from the server to see if there is additional information and to also know which operation is failing see  http://msdn.microsoft.com/en-us/library/office/dd633676(v=exchg.80).aspx

    You might also want to do some testing with the EWSEditor http://ewseditor.codeplex.com/

    There also should be an EWSLog on the CAS server where the requests are being sent so this is worth looking at as well eg \Microsoft\Exchange Server\V14\Logging\Ews

    As a workaround with the failed messages you might want to trying getting the MimeContent and forwarding that instead of using the Forward operation

    Cheers
    Glen

    Tuesday, June 10, 2014 5:10 AM
  • As I noted in the code comments, CreateForward() is useful in this context because it manages the attachments for me. Earlier in the development cycle I tried creating an EmailMessage() from scratch and populating it with the data from the original message, but found that no matter what I did the attachments would get mangled, leading to other "Data is corrupt" messages.

    I tried EWSEditor, but I'll have a look at the tracing and the logs.

    Tuesday, June 10, 2014 3:50 PM
  • >> As I noted in the code comments, CreateForward() is useful in this context because it manages the attachments for me

    If you use the MimeContent this will also include the attachments, it's hard to comment without being able to see the actual content of the message. What type of attachments are they ? If EWS can't process the messages because of some particular content (eg if its a bug in EWS itself when processing this content) then the only thing you maybe able to do is make sure you have the latest service packs and rollups applied. If so and you can still reproduce the error log a support call with microsoft with the bug and reproduction and hopefull it maybe something that can be fixed in future rollups. If they are just regular RFC Mime messages then using the Mimecontent as a workaround should work.

    Cheers
    Glen

    Wednesday, June 11, 2014 5:43 AM
  • I finally solved the problem. It wasn't the message content, or the attachments. They were red herrings. The problem was the value I was using for the ReplyTo.

    This application is an update of an older one that was written with MAPI. With MAPI, mail addresses could be in a variety of forms, including names, as in "John <space> Doe". However, EWS apparently requires that email addresses be email addresses. So, when the replyTo parameter was "John <space> Doe", the send would fail with the unhelpful "Data is Corrupt" error message. Changing the value to "jdoe@myorganization.com" fixed the problem.

    I realized this after poring over the trace logs. That turned out to be really, really helpful. Though a hard slog - EWS is a really chatty protocol.

    Thursday, June 12, 2014 11:57 PM
  • Mine was similar.  There was a rogue space character at the end of the From address.  Worked fine under SMTP, didnt work under EWS.
    Wednesday, October 5, 2016 1:52 PM