'Hiding custom ItemProperties from print. Interop.Outlook

I have written an Outlook plugin that basically allows emails being received through Outlook to be linked with a website so that the email can also be view in the communications feature of the website. I store additional details within the ItemProperties of a MailItem, these details are basically things like the id of the user the email relates to within a website.

The problem I'm having is any ItemProperties I add to a MailItem are being printed when the email is printed. Does anyone know how to exclude custom ItemProperties when printing an email?

Here is the code that is creating the custom ItemProperty:

// Try and access the required property.
Microsoft.Office.Interop.Outlook.ItemProperty property = mailItem.ItemProperties[name];

// Required property doesnt exist so we'll create it on the fly.
if (property == null) property = mailItem.ItemProperties.Add(name, Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);

// Set the value.
property.Value = value;


Solution 1:[1]

I'm working on Outlook extension and sometimes ago we had the same issue. One of our team members found a solution. You can create some method which is responsible for disable printing. You can see peace of our code below:

public void DisablePrint()
{
    long printablePropertyFlag = 0x4; // PDO_PRINT_SAVEAS
    string printablePropertyCode = "[DispID=107]";
    Type customPropertyType = _customProperty.GetType();

    // Get current flags.
    object rawFlags = customPropertyType.InvokeMember(printablePropertyCode , BindingFlags.GetProperty, null, _customProperty, null);
    long flags = long.Parse(rawFlags.ToString());

    // Remove printable flag.
    flags &= ~printablePropertyFlag;

    object[] newParameters = new object[] { flags };

    // Set current flags.
    customPropertyType.InvokeMember(printablePropertyCode, BindingFlags.SetProperty, null, _customProperty, newParameters);
}

Make sure that _customProperty it is your property which you created by the following code: mailItem.ItemProperties.Add(name,Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);

Solution 2:[2]

On the low (Extended MAPI) level, each user property definition has a flag that determines whether it is printable (namely, PDO_PRINT_SAVEAS). That flag however is not exposed through the Outlook Object Model.

You can either parse the user properties blob and manually set that flag (user properties blob format is documented, and you can see it in OutlookSpy (I am its author) if you click the IMessage button) or you can use Redemption (I am also its author) and its RDOUserProperty.Printable property.

The following script (VB) will reset the printable property for all user propeties of the currently selected message:

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set Msg = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
  for each prop in Msg.UserProperties
     Debug.Print prop.Name
     prop.Printable = false
  next
  Msg.Save

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aliaksei Futryn
Solution 2 Dmitry Streblechenko