We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Fetch from EWS, after Outlook UserProperties when sending, no longer working

In C#, using a licensed version from 2016, just upgraded to the latest, and it broke the API pretty good. Used to be able to set UserProperties (storing a number Id to find a sent email later) from a C# client that launched Outlook. Then fetching from EWS on a service I could get the value from the Exchange server to then find that email specifically.

The client does this:

public void Set(int aId, Microsoft.Office.Interop.Outlook.MailItem aMessage)
{
Microsoft.Office.Interop.Outlook.UserProperty property = aMessage.UserProperties[_PropertyName];

        if (property == null)
            property = aMessage.UserProperties.Add(_PropertyName, Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, System.Type.Missing, System.Type.Missing);

        property.Value = aId.ToString();
        
        aMessage.Save();            
    }

Then later in Aspose after fetching from EWS:

Aspose.Email.MailMessage.Headers[“SomePropertyName”] since when I fetched I could just pass a string property name to the extended properties parameter.

What is the new way to do this? The user has to launch Outlook so they can tweak their email, send it, then I want to grab it on the backend later and upload the actual email they sent to our doc management system to prove they sent it for auditing/regulatory reasons.

Thanks! Been using Aspose licensed for over 10 years!

@NWALAB

For working with Outlook, you may follow the link given below:
https://docs.aspose.com/display/emailnet/Working+with+Outlook+Items

For setting mail headers, please follow the code sample given below:

mailMessage.Headers.Add("secret-header", "mystery");

You may find more details at this link: https://docs.aspose.com/display/emailnet/Creating+and+setting+contents+of+Emails

Moreover, mailMessage.MessageId can be used to get message ID.

Thanks for the links, but it was already working through Aspose Email .Net 2016.09.08.

The Id comes from a sql database, in order to link to that email so I know where to store it later in a separate doc management system. I need to launch the email from Outlook (interop right now) and then the user can tweak the email send it, not send it, whatever, then in EWS, I dig it out from a separate windows service and extract that Id and then upload it to another database. Thanks.

Looks like I can set a header instead of a user property in interop land on the message. Then on the latest Aspose Ic an pull that header by name.

public void Set(int aId, Microsoft.Office.Interop.Outlook.MailItem aMessage)
{
aMessage.PropertyAccessor.SetProperty(“[http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/MyPropertyNameIdHere](http://schemas.microsoft.com/mapi/string/%7B00020386-0000-0000-C000-000000000046%7D/MyPropertyNameIdHere)”, aId.ToString());
aMessage.Save();
}

then read:

public int Get(Aspose.Email.MailMessage aMailMessage)
{
int result = -1;


        string customPropertyValue = aMailMessage.Headers[MyPropertyNameIdHere];

        if ((customPropertyValue != null) && (customPropertyValue != string.Empty))
        {            
            result = Convert.ToInteger(customPropertyValue);
        }           

        return result;
    }

x

@NWALAB

Thank you for writing to us. I am afraid we may not guide with the functionality of Interop but yes you have found a solutions. We are happy for your feedback and we may add an article to our API related to this.