none
[E2010] [EWSMA] [C#]: Is is possible to always load MimeContent? RRS feed

  • Question

  • I am trying to access the MimeContent for email messages that I process via the managed api.  I have noticed that even if I load properties for the MimeContent it doesn't exist for one message.  The message apparently missing mime content is an automated reply from Exchange (because an address didn't exist).
    My highlevel goal is to get to a RFC822 format of the message, which is why I am trying to get the MimeContent.
    Is this normal, and is there a workaround to get to the RFC822 format in these cases?
     
    public void ProcessEmails(ExchangeService service, IEnumerable<EmailMessage> messages)
    {
     var properties = new PropertySet()
           {
            ItemSchema.ItemClass,
            ItemSchema.MimeContent,
            ItemSchema.Subject,
            EmailMessageSchema.From,
           };
    
     service.LoadPropertiesForItems(messages, properties);
    
     foreach(var message in messages)
     {
      ProcessEmail(message);
     }
    }
    
    public void ProcessEmail(EmailMessage email)
    {
     email.IsRead = true;
    
     var rfc822 = email.MimeContent.ToString(); <- Exception here for some, not all message
    

    Monday, June 13, 2011 2:27 PM

Answers

  • That might be possible.  My experience is within an Exchange dev world wherein all Exchange servers are within the same forest.  In that world, everything that I send in from the outside is always in Mime, while everything that I send from Outlook to another Exchange mailbox is TNEF.  If I send from Outlook to a non-Exchange recipient, Mime is used.

     

    If your goal is to get an RFC822 (i.e., mime) format for all messages, you will encounter TNEF in the wild, and you will have to deal with it somehow, either by crafting your own TNEF-Mime converter or ignoring TNEF messages.  You might find a 3rd-party converter, but I didn't.  I wanted to do the same thing as you (for a Transport Agent I've written) and I spent a few days researching this situation before I gave up; actually, I discovered that for my purpose, I didn't need Mime for my purpose, so all was good.  Still, during my search, I discovered other developers who were looking to do this (convert Tnef to Mime) and were faced with the same frustration as me.  I even found one guy who said he had discovered a private api (using reflection) with the Exchange DLL's that would do it, but I would not use private API's in a commercial product, so I didn't go there!

     

    Remember that there are public APIs available within Exchange that will decant all parts of any message, Mime or Tnef.  Using these, you might be able to craft your own conversion, by first decanting all parts of the Tnef message, then re-assembling those parts using the Mime API's included with Exchange.

     

    rob

     

    Friday, June 17, 2011 6:19 PM

All replies

  • I suspect that what you're seeing is a message that is not encoded in Mime.  Not all items travelling thru Exchange are in Mime.  Microsoft often will encode a message using their TNEF (Transport Neutral Encoding Format) format.  If that's what you've got here, you won't be able to easily convert it to Mime (although it is possible).

     

    See if the messasge item has a property named 'TnefPart' that is not null.  If so, then you have a TNEF-encoded item, and you'll have to deal with it differently.  

     

    Rob

    Wednesday, June 15, 2011 4:27 PM
  • Thanks Rob.  Is it possible for an external email (external to the domain and exchange, but could originate from someone else's exchange server) to use TNEF, or will all incoming email have be in MIME.  I'm assuming so because I think its an internet standard.

    If that's the case I won't encounter this scenario in the wild (only in testing I suppose) and so I can be more relax have dealing with it.

    Paul

    Thursday, June 16, 2011 7:56 PM
  • That might be possible.  My experience is within an Exchange dev world wherein all Exchange servers are within the same forest.  In that world, everything that I send in from the outside is always in Mime, while everything that I send from Outlook to another Exchange mailbox is TNEF.  If I send from Outlook to a non-Exchange recipient, Mime is used.

     

    If your goal is to get an RFC822 (i.e., mime) format for all messages, you will encounter TNEF in the wild, and you will have to deal with it somehow, either by crafting your own TNEF-Mime converter or ignoring TNEF messages.  You might find a 3rd-party converter, but I didn't.  I wanted to do the same thing as you (for a Transport Agent I've written) and I spent a few days researching this situation before I gave up; actually, I discovered that for my purpose, I didn't need Mime for my purpose, so all was good.  Still, during my search, I discovered other developers who were looking to do this (convert Tnef to Mime) and were faced with the same frustration as me.  I even found one guy who said he had discovered a private api (using reflection) with the Exchange DLL's that would do it, but I would not use private API's in a commercial product, so I didn't go there!

     

    Remember that there are public APIs available within Exchange that will decant all parts of any message, Mime or Tnef.  Using these, you might be able to craft your own conversion, by first decanting all parts of the Tnef message, then re-assembling those parts using the Mime API's included with Exchange.

     

    rob

     

    Friday, June 17, 2011 6:19 PM