Outlook field printing suppression

We have created an add-in for Outlook that sends emails to our CRM system. In the process, it saves the Outlook message identifier as a UserField in the message itself.

eg.

currentUserProperty = Constants.APPLICATION_NAME + "EntryID";
mailItem.UserProperties.Add(currentUserProperty,
       Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText,
       Missing.Value,
       Missing.Value).Value = entryId;

Sorry, this is the HUUUGGEE number, like:

"00000000D502D779150E2F4580B1AADDF04ECDA6070097EF5A1237597748A4B4F9BFF540020800000006E9E4000068BB5B6DFC36924FAEC709A17D056583000002DE0E350000"

The problem is that when the user types the message, Outlook insists on including this field (below / From) and because it has no spaces, it cannot wrap the identifier and compress the A4 page until it fits horizontally, This creates tiny printouts of email.

Is there any way to fix this? I was thinking of rewriting the OriginalEntryID field (which causes the problem) with one space separator, but I am getting an exception from the COM level. My next stop is to try disabling the output of this and other custom fields in Outlook.

Does anyone know how this can be achieved?

+3
source share
2 answers

You must use .NET Reflection to fix this (as recommended by Microsoft Support). Hopefully this will be fixed in future versions of the VSTO SDK.

Suppress Outlook user field printing

static void SuppressUserPropertyPrinting(Outlook.MailItem message)
{
    try
    {   // Late Binding in .NET: https://support.microsoft.com/en-us/kb/302902
        Type userPropertyType;
        long dispidMember = 107;
        long ulPropPrintable = 0x4; // removes PDO_PRINT_SAVEAS
        string dispMemberName = String.Format("[DispID={0}]", dispidMember);
        object[] dispParams;

        if (message.UserProperties.Count == 0) return; // no props found (exit)

        // marks all user properties as suppressed
        foreach (Outlook.UserProperty userProperty in message.UserProperties.Cast<Outlook.UserProperty>())
        {
            if (userProperty == null) continue; // no prop found (go to next)
            userPropertyType = userProperty.GetType(); // user property type

            // Call IDispatch::Invoke to get the current flags
            object flags = userPropertyType.InvokeMember(dispMemberName, BindingFlags.GetProperty, null, userProperty, null);
            long lFlags = long.Parse(flags.ToString()); // default is 45 - PDO_IS_CUSTOM|PDO_PRINT_SAVEAS|PDO_PRINT_SAVEAS_DEF (ref: http://msdn.microsoft.com/en-us/library/ee415114.aspx)

            // Remove the hidden property Printable flag
            lFlags &= ~ulPropPrintable; // change to 41 - // PDO_IS_CUSTOM|PDO_PRINT_SAVEAS_DEF (ref: http://msdn.microsoft.com/en-us/library/ee415114.aspx)

            // Place the new flags property into an argument array
            dispParams = new object[] { lFlags };

            // Call IDispatch::Invoke to set the current flags
            userPropertyType.InvokeMember(dispMemberName, BindingFlags.SetProperty, null, userProperty, dispParams);
        }
    }
    catch { } // safely ignore if property suppression doesn't work
}
+14

Source: https://habr.com/ru/post/1705659/


All Articles