Issue with Deleting Contacts and Error in Aspose.Email 23.8

Dear Aspose Support Team,

We are currently using Aspose.Email to interact with Outlook contacts in our application. Specifically, we are attempting to delete contact items using the DeleteItem method provided by Aspose.Email.

Here’s the code we are using:

client.DeleteItem(OutlookID, DeletionOptions.DeletePermanently);

This code works perfectly fine for older versions of Outlook, but we are facing an issue when trying to delete contacts in the web version. The contacts do not get deleted, and we do not receive any error messages or exceptions.

We would greatly appreciate your assistance in troubleshooting this issue. Can you please provide guidance on how to ensure contact deletion works consistently across different versions of Outlook, including the web version?

If there are any code changes or configurations we need to make to address this issue, please let us know. We are eager to resolve this problem and ensure the reliable deletion of contacts across all Outlook versions.

Additionally, we’d like to bring to your attention another issue. When we upgraded to Aspose.Email version 23.8, we encountered the following error related to the code snippet below:

image.png (11.0 KB)

Contact con = client.GetContact(OutlookID, ExchangeListContactsOptions.None);
MapiContact _c = (MapiContact)con;
_c.PhysicalAddresses.WorkAddress.IsMailingAddress = check1 == 1 ? true : false;

the error occurs in the code: sID = client.CreateItem(client.GetMailboxInfo(senderEmail).ContactsUri, _c);

Can you please assist us in resolving this issue as well?

Thank you for your prompt attention to these matters. We look forward to your guidance and assistance.

Best regards,

Hello @deltaaccess,

Thank you for contacting our support team.
We have opened the following new ticket(s) in our internal issue tracking system and will investigate the issues.

Issue ID(s): EMAILNET-41176,EMAILNET-41177

Sorry for the inconvenience.

Hi @deltaaccess
We did some testing but were unable to reproduce your error, on our side all works correctly. We have created a simple test application with the scenario you described, please insert your credentials and try it on your end. Feel free to edit this application so we can reproduce the bug and send it to us. Thank you for your cooperation.EmailTestEWS2.zip (15.0 KB)

Hi,
here is the edited Aspose code.

Regards,

@deltaaccess,

Thank you, for the updated project, we’ll continue investigating.

Hi @deltaaccess
The issue with creating contacts has been reproduced and fixed. A fix will be available in a near release.
Unfortunately, we are still unable to reproduce your issue with deleting contacts on our side. It would be nice if you could give us a test account to reproduce the problem. If not, we can recommend trying the following options:
1.After deleting a contact, try to check its presence using your code and not in the browser.
2.Set permission ‘full_access_as_app’ in the ‘Office 365 Exchange Online’ group for your application.
3. Use to get token the ConfidentialClientApplicationBuilder from the MSAL.NET library(see sample code in simple app that I sent to you early).

Thank you for your cooperation and please share your feedback.

The problem with deleting can be considered as resolved i guess, however there is another problem:

Description of the Issue:

I have been using Aspose.Email version 23.10 to create and manage contacts in Outlook. The contacts are created with a named property, “argowebid,” to uniquely identify them. Additionally, I have implemented logic to check whether a contact already exists based on this named property. If a contact is found, it should be updated, and if not, a new contact should be created.

Problem Encountered:

Upon testing, I observed that the contact detection logic is not functioning as expected. Even when a contact with the specified “argowebid” exists, the system is not able to find it, and a new contact is created instead of updating the existing one.

Code Snippet:

I am sharing a simplified version of the code for your reference:

csharpCopy code
check if contact exsists

foreach (MapiContact con in contacts)
{
    string _debugName = $"{con.NameInfo.Surname}, {con.NameInfo.GivenName}";
    if (con.NamedProperties.Any(x => x.Value?.Name == "argowebid" && x.Value.GetString() == _contactItem.oid.ToString()))
    {
        return new Tuple<bool, bool, string>(true, true, ((Contact)con).Id.EWSId);
    }
    else if (con.NamedProperties.Any(x => x.Value is MapiNamedProperty && (x.Value as MapiNamedProperty).NameId == "argowebid"))
    {
        IEnumerable<MapiNamedProperty> _list = con.NamedProperties.Where(x => x.Value is MapiNamedProperty && (x.Value as MapiNamedProperty).NameId == "argowebid").Select(x => x.Value as MapiNamedProperty);
        foreach (MapiNamedProperty _p in _list)
        {
            if (_p.GetString() == _contactItem.oid.ToString())
                return new Tuple<bool, bool, string>(true, true, ((Contact)con).Id.EWSId);
        }
    }
}

return new Tuple<bool, bool, string>(true, false, "");

creation of a named Property for new contact

MapiContact _c = new MapiContact();
string sID = "";
           
try
{
    mapArgoToMapiContact(_contactItem, ref _c);

    if (_contactItem.oid > 0)
    {
        Guid PS_PUBLIC_STRINGS = new Guid("00020329-0000-0000-C000-000000000046");
        MapiProperty stringProperty = new MapiProperty(_c.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE), System.Text.Encoding.Unicode.GetBytes(_contactItem.oid.ToString()));
        _c.SetProperty(stringProperty);
        string stringNameId = "argowebid";
        _c.NamedPropertyMapping.AddNamedPropertyMapping(stringProperty, stringNameId, PS_PUBLIC_STRINGS);

        _c.SubStorages.Add(stringProperty);
    }

    sID = client.CreateItem(client.GetMailboxInfo(senderEmail).ContactsUri, _c);     

Expected Behavior:

The system should correctly identify and update existing contacts based on the named property (“argowebid”).

Additional Information:

  • tests are made with Aspose.Email Version: 23.10
  • last version when the code worked: 22.9

Please Advise.

Thank you,

Hello @deltaaccess,

Thank you for the detailed info about the issue.

We have opened the following new investigation ticket in our internal issue tracking system and will investigate this issue.

Issue ID(s): EMAILNET-41231

Sorry for the inconvenience this may cause.

Hi @deltaaccess
Unfortunately, you did not provide an example of code for obtaining a list of contacts and we were not able to check on our side how your code works with version 22.9. To receive custom properties from the server, you must specify a list of these properties. Below is the code that works for all versions in our case. Please check and give feedback.

            Console.WriteLine("Getting access token...");
            OAuthNetworkCredential oAuthcredentials = GetAccessTokenWithClientCredentials().ConfigureAwait(false).GetAwaiter().GetResult();
            Console.WriteLine("Getting client 365...");
            IEWSClient client365 = EWSClient.GetEWSClient(Settings.ExchangeWSUrl, oAuthcredentials);

            MapiContact _c = new MapiContact("Some Contact 8888888888888", "cvb@nnn.com");

            Guid PS_PUBLIC_STRINGS = new Guid("00020329-0000-0000-C000-000000000046");
            string stringNameId = "argowebid";
            long tag = _c.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE);

            //MapiProperty stringProperty = new MapiProperty(tag, Encoding.Unicode.GetBytes("8888888888888"));
            //_c.SetProperty(stringProperty);
            //_c.NamedPropertyMapping.AddNamedPropertyMapping(stringProperty, stringNameId, PS_PUBLIC_STRINGS);
            //_c.SubStorages.Add(stringProperty);

            MapiNamedProperty stringProperty = new MapiNamedProperty(tag, stringNameId, PS_PUBLIC_STRINGS,
                Encoding.Unicode.GetBytes("8888888888888"));
            _c.SetProperty(stringProperty);
            _c.NamedPropertyMapping.AddNamedPropertyMapping(stringProperty, stringNameId, PS_PUBLIC_STRINGS);

            string folderId = client365.GetMailboxInfo().ContactsUri;

            string sID = client365.CreateItem(folderId, _c);

            List<PropertyDescriptor> properties = new List<PropertyDescriptor>();
            properties.Add(stringProperty.Descriptor);
            var contacts = client365.ListContacts(folderId, properties);

            Console.WriteLine("ListContacts - " + contacts.Length);

            foreach (MapiContact con in contacts)
            {
                if (con.NamedProperties.Any(x => x.Value is MapiNamedProperty && (x.Value as MapiNamedProperty).NameId == "argowebid"))
                {
                    IEnumerable<MapiNamedProperty> _list = con.NamedProperties.Where(x => x.Value is MapiNamedProperty && (x.Value as MapiNamedProperty).NameId == "argowebid").Select(x => x.Value as MapiNamedProperty);
                    foreach (MapiNamedProperty _p in _list)
                    {
                        if (_p.NameId == "argowebid")
                        {
                            Console.WriteLine(con.NameInfo.DisplayName);
                            Console.WriteLine($"{_p.NameId}, {_p.GetString()}");
                        }
                    }
                }
            }