none
[E2010][EWSMA][VB.NET] Resulting EML file after save contains empty "Reply-To" RRS feed

  • Question

  • When saving an email message that has been retrieved from Exchange with the managed EWS API, the resulting EML file contains an empty Reply-To field. This causes Outlook to display an empty To field when pressing reply in such an EML file.So when i double click this eml it opens and shows correctly in Outlook, but when i press Reply the resulting To field becomes empty. If i manually remove this empty Reply-To field in the eml file, then the To field is filled with the original sender, which is the behavior im looking for. What can i do to get rid of this empty reply-to field?

    ps = New PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent, EmailMessageSchema.Sender, EmailMessageSchema.ReplyTo)

    ''Updated, replaced this code with line above

    ''ps = New PropertySet(ItemSchema.MimeContent) ''ps.Add(EmailMessageSchema.Sender)

    TempMsg = EmailMessage.Bind(cl, New ItemId(Msg.Id.UniqueId), ps) System.IO.File.WriteAllBytes(file, TempMsg.MimeContent.Content)


    MIME-Version: 1.0
    Reply-To:
    Content-Type: multipart/related;





    • Edited by Joost Aarts Wednesday, August 14, 2013 6:16 PM
    Wednesday, August 14, 2013 4:39 PM

All replies

  • Hello Joost Arts,

    binding the message will give you a full email object with only the fields you specified in the propertyset loaded. The object will still have the properties you did not ask for (which - as their content has not been loaded - have the value null). Depending on how System.IO.File.WriteAllBytes(...) works, it may well add nulled parameters into the structure as well, which your outlook interpretes as an empty reply-to.

    Given that probable event I see two ways to go about it:

    1) Automate removing the Reply-To field after writing the file by using whatever means VB offers you (you'll know more about that than I do).

    2) Try loading the reply-to property as well, which ought to add in the sender there as well. This ought to make your Outlook accept it as well. That change ought to look like this in your code:

    ps = New PropertySet(ItemSchema.MimeContent)
    ps.Add(EmailMessageSchema.Sender)
    ps.Add(EmailMessageSchema.ReplyTo)
    TempMsg = EmailMessage.Bind(cl, New ItemId(Msg.Id.UniqueId), ps)
    System.IO.File.WriteAllBytes(file, TempMsg.MimeContent.Content)
    Hope it works and helps,
    Fred

    • Edited by FWN Wednesday, August 14, 2013 5:22 PM
    Wednesday, August 14, 2013 5:21 PM
  • Hi Fred,

    Thanks for taking time to respond. Adding the property doesnt seem to help, the created eml contains an empty reply-to field

    ps = New PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent, EmailMessageSchema.Sender, EmailMessageSchema.ReplyTo)

    The writeallbytes is just a framework function that writes an array of bytes to a file. I could do some post processing on the file, but that is something i would like to avoid, i have no idea what exotic encodings i would have to support.

    Wednesday, August 14, 2013 6:14 PM
  • Hi Joost,

    hm, if that doesn't work, the only thing I can think of to get it filled is to create the emailaddress collection and set the ReplyTo property with it. Not quite sure how it ought to be written in VB.NET, but my guess would be to add this after binding the item (load the sender, skip the replyto property):

    rep = New EmailAddressCollection
    rep.Add(TempMsg.Sender)
    TempMsg.ReplyTo = rep

    before you write it to file.

    Hope that worked,
    Fred

    P.s.: To make looking it up easier: Here's the EmailAddressCollection definition


    There's no place like 127.0.0.1

    Wednesday, August 14, 2013 6:42 PM

  • I had tried that earlier but no luck... i think MimeContent is being generated and retrieved from the server and ignores any properties being modified on the client
    Wednesday, August 14, 2013 7:37 PM
  • :(

    The only idea I have left would be to actually update the ReplyTo property to the exchange-stored item. Can't say I know what consequences that may or may not entail though.


    There's no place like 127.0.0.1

    Wednesday, August 14, 2013 8:13 PM
  • Whenever you request the MimeContent in EWS an "on the fly" content conversation is done. I'd suggest having a read of http://msdn.microsoft.com/en-us/library/hh545614(v=exchg.140).aspx . You might want to use a Mapi Editor like OutlookSpy of MFCMapi to have a look at the PidTagMimeSkeleton property which is where the headers should be stored and retrieved during the content conversion.

    One thing to note if the message your working with wasn't delivered to store normally (eg if it was uploaded for example) than that property wouldn't be set correctly and some header loss is what you would expect.

    Cheers
    Glen 

    Thursday, August 15, 2013 4:17 AM
  • @Fred Thanks for the effort anyway, its much appreciated.

    Glen after playing around with the suggestions in the link you posted it works now, but im not sure anymore what it was that did the trick. Thanks
    • Edited by Joost Aarts Thursday, August 15, 2013 3:32 PM
    Thursday, August 15, 2013 8:56 AM