none
Outlook > Add-In > Mail Item > How to save the mail item (which is in compose mode) as a .msg file in non editable form? RRS feed

  • Question

  • Hello,

    I am working on an outlook add-in where I have a custom button on the ribbon tab of compose mail item.

    My requirement is to save the mail item currently being composed as a .msg file at a predefined location on click of my custom "Save" button. I am able to do it using "mailItem.SaveAs(...)".

    But my problem is, when I open the .msg file in outlook, it is opened in compose mode but I want to see it as a read-only item. For e.g. exactly the way it looks when I save it after it's sent.

    Could you share any ideas on how to achieve this?

    Thanks,

    Vinay


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Wednesday, March 4, 2015 8:46 AM

Answers

  • Strictly speaking you need to *remove* the MSGFLAG_UNSENT bit (=8), not set the MSGFLAG_READ bit, so setting the PR_MESSAGE_FLAGS property to either 0 or 1 will work. Keep in mind that you can remove the MSGFLAG_UNSENT bit only before the message is saved for the very first time. If you touch the bit after the message was saved, the message will stay unsent.

    Also note that this may not be what the user wants since the message will become read-only when reopened.


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

    Wednesday, March 4, 2015 1:53 PM

All replies

  • Hello Vinay,

    The Outlook object model doesn't provide any property or method for that. But you can set a low-level property - PR_MESSAGE_FLAGS (the DASL name is "http://schemas.microsoft.com/mapi/proptag/0x0E070003"). You can use the PropertyAccessor class to get the job done in Outlook 2007 and later. In earlier Outlook versions you need to use a low-level code (Extended MAPI) or any other third-party wrappers around that API.

    You need to set the MSGFLAG_READ value (corresponds to 1) for showing the item using the read mail inspector window. Don't forget to set sender related properties before showing the mail as read-only.

    Wednesday, March 4, 2015 9:40 AM
  • Hello Eugene,

    Thanks for sharing your views.

    Please note that the link to DASL name is not working.

    Also, could you please elaborate more on - "Don't forget to set sender related properties before showing the mail as read-only."

    Thanks!


    -Vinay Pugalia
    If a post answers your question, please click "Mark As Answer" on that post or "Vote as Helpful".
    Web : Inkey Solutions
    Blog : My Blog
    Email : Vinay Pugalia

    Wednesday, March 4, 2015 10:18 AM
  • Vinay,

    > Please note that the link to DASL name is not working.

    It is not a link actually. You should pass that string to set the property using the PropertyAccessor object.

    > Also, could you please elaborate more on - "Don't forget to set sender related properties before showing the mail as read-only."

    The corresponding fields in the UI will be empty if you don't set sender related properties.

    Wednesday, March 4, 2015 10:21 AM
  • Strictly speaking you need to *remove* the MSGFLAG_UNSENT bit (=8), not set the MSGFLAG_READ bit, so setting the PR_MESSAGE_FLAGS property to either 0 or 1 will work. Keep in mind that you can remove the MSGFLAG_UNSENT bit only before the message is saved for the very first time. If you touch the bit after the message was saved, the message will stay unsent.

    Also note that this may not be what the user wants since the message will become read-only when reopened.


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

    Wednesday, March 4, 2015 1:53 PM