none
MailItem.Save / msg opened from disk / Editing attachments RRS feed

  • Question

  • Hello,

    I am a bit puzzled with the behaviour of MailItem.Save. When a msg-file is opened from disk and the body or subject is edited in Outlook, calling Save on the MailItem persists the changes on disk. However, once an attachment is added to the MailItem, a new conversation is created in the user's inbox. At this point the MailItem also gets an EntryID. Now, calling Save no longer persists the changes on the msg-file. Now this is something I have to take into account - so what are the different changes than result in new conversation being created?

    Tuesday, October 21, 2014 8:34 AM

All replies

  • Hello,

    The conversation grouping is based on the normalized subject (without RE or FW prefixes) with timestamp markers. If you change it the Outlook item will not be added to the existing conversation.

    > Now, calling Save no longer persists the changes on the msg-file.

    The Save method doesn't do anything with msg files. To apply changes to the msg file file you need to use the SaveAs method instead.  

    Tuesday, October 21, 2014 8:54 AM
  • The Save method doesn't do anything with msg files. To apply changes to the msg file file you need to use the SaveAs method instead.  

    That has been my understanding also. But I am seeing the very opposite effect. When I edit the email body & programmatically call Save on MailItem, the file changes on disk. I verified this by taking MD5 hashes.

    Now, if I add an attachment to the MailItem created from msg file (i.e. double from disk to open), then a new draft item is created in my inbox. Upon this point, I indeed need to use SaveAs. It is also at this point that the Mailitem has an EntryId.

    The following conversation refers to the same effect:

    https://social.msdn.microsoft.com/Forums/office/en-US/bed6509c-00ee-4bf4-9ed9-4a91b7dc47df/adding-attachment-creates-new-mailitem-in-inbox-folder?forum=outlookdev

    Tuesday, October 21, 2014 8:58 AM
  • What exactly do you need to implement?

    What is the final goal of your code? Why do you need to add attachments to the opened item programmatically?

    Tuesday, October 21, 2014 9:07 AM
  • I don't need to. But the user might have modified the attachments. The process is that user opens an msg file, then modifies the email, after which my code kicks in & saves the file on disk & to other systems from there. This is where I currently have to check whether the Mailitem, produced from msg file, has an EntryId and whether I need to Save or SaveAs (I know the path to the msg file from which the Mailitem was produced and I need to overwrite the changes to that source file).
    Tuesday, October 21, 2014 9:24 AM
  • When you open an MSG file, Outlook always create a temporary copy in the Inbox folder, then displays that copy. There is no way to check if a particular message was opened from an MSG file.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 22, 2014 5:50 AM
  • When you open an MSG file, Outlook always create a temporary copy in the Inbox folder, then displays that copy. There is no way to check if a particular message was opened from an MSG file.



    Indeed with VSTO it isn't possible. I have other means of tracking that information (the information is also resident it Outlook's memory as can be verified by a mem dump). However, as I've said, I only see the temporary copy appear in the Inbox if the user adds an attachment to the email. Before that, if only recipient / subject / body are modified, the temporary copy does not appear & the EntryId of the MailItem is null. At this point, calling MailItem.Save also modifies the msg file on disk.
    Wednesday, October 22, 2014 6:55 AM