Custom User Properties not appearing for the recipient

Add-in Express™ Support Service
That's what is more important than anything else

Custom User Properties not appearing for the recipient
Custom User Properties not appearing for the recipient 
Sujay Ghosh




Posts: 27
Joined: 2010-01-20
Hello

Sender --> abc@yourcompany.com
Recipient --> xyz@mycompany.com

I am saving the ADXForm values in UserProperties , and it is being saved properly. It also appears in the Sent item mail.


private void OnEmailSend(object sender, AddinExpress.MSO.ADXOlItemSendEventArgs e)
{
ADXOlForm olForm = (ADXOLXtraInfo)adxOlFormsCollItem.GetForm(ADXOLXtraInfo.AdxInspectorObject);


if (olForm != null && e.Item is Outlook.MailItem)
{
ADXOLXtraInfo xtraForm = (ADXOLXtraInfo)olForm;

var mItem = e.Item as Outlook.MailItem;

var customUserProperty = xtraForm.OLMailItem.UserProperties.Find("MyCustomProperty", true);

if (customUserProperty == null)
{
StringBuilder sb = new StringBuilder();
string customValues = string.Empty;

// more code

customValues = sb.ToString();

customUserProperty = mItem.UserProperties.Add("MyCustomProperty", Outlook.OlUserPropertyType.olText, false, 1);
customUserProperty.Value = customValues;

}
else
customUserProperty.Value = xtraForm.CustomValues;

mItem.Save();
}

But when recipient opens the above email, the user properties are not avialable.


In my code I checking for the userproperty values in

private void ADXOLXtraInfo_ADXBeforeFormShow()

customUserProperty = OLMailItem.UserProperties.Find("MyCustomProperty", true);


But for the recipient customUserProperty is returning NULL

I have checked this using Outlookspy and while the customproperty shows up for the sent item, it does not show up for the recipient

What can be the problem

Thank you
Sujay
Posted 04 Mar, 2023 13:22:55 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Sujay,

Note that each call to OLMailItem.UserProperties.Find() and mItem.UserProperties.Add() in the code fragments above creates and leaves unreleased two COM objects:
- the UserProperty object that UserProperties.Find() or mItem.UserProperties.Add() return
- the COM object representing a collection of UserProperty objects on a MailItem.

Leaving these COM objectd unreleased may cause issues that you prevent by releasing the corresponding variables after use. To be able to release the UserProprties object, store it in a separate variable.

Find more details in section Release all COM objects created in your code; see the PDF file in the folder {Add-in Express}\Docs on your development PC.

Sujay Ghosh writes:
But for the recipient customUserProperty is returning NULL


This is expected: Outlook doesn't transfer UserProperty object to recipients; see https://support.microsoft.com/en-us/topic/changes-to-custom-properties-in-outlook-f1caa232-60a3-0526-068c-d5eeec8b3752. For a workaround, see https://www.add-in-express.com/forum/read.php?FID=5&TID=14156.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Mar, 2023 03:58:46 Top
Sujay Ghosh




Posts: 27
Joined: 2010-01-20
Hello Andrei ,

Thank you very much . I shall change the code accordingly

Regarding the ReleaseComObjects, shall the following be the recommended way for Add and Find

customUserProperty = mItem.UserProperties.Add("MyCustomProperty", Outlook.OlUserPropertyType.olText, false, 1);
customUserProperty.Value = customValues;

mItem.Save();

if(customUserProperty !=null )
Marshal.ReleaseComObject(customUserProperty )

Thank you
Sujay
Posted 06 Mar, 2023 12:13:34 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Sujay,


Outlook.UserProperty customUserProperty = null;
Outlook.UserProperties userProperties = null; 

try 
{
    userProperties = mItem.UserProperties;
    customUserProperty = userProperties.Add("MyCustomProperty", Outlook.OlUserPropertyType.olText, false, 1);
    customUserProperty.Value = customValues;
    mItem.Save();
}
catch (Exception ex) 
{
    // log the exception; otherwise you won't know about it
}
finally 
{
    if (userProperties !=null) Marshal.ReleaseComObject(userProperties); 
    if (customUserProperty !=null) Marshal.ReleaseComObject(customUserProperty); 
}


Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 07 Mar, 2023 03:38:25 Top
Sujay Ghosh




Posts: 27
Joined: 2010-01-20
Hello Andrei,


Thank you . For me to use PropertyAccessor , I need to update the Addin Express interops from 2000 to 2007 .
I have posted another topic for that https://www.add-in-express.com/forum/read.php?FID=5&TID=16511&MID=85743#message85743.
Posted 10 Mar, 2023 12:06:18 Top