Office 365 - IMAP Delete Message Issue

Hello!

We’re having a problem deleting messages when connected to Office 365 via IMAP (using Aspose version 6.7.0.0)

We call this:
_AsposeImapClient.DeleteMessage(_ImapMessage.UniqueId)
_AsposeImapClient.CommitDeletes()

And we receive this error:
AE0035 NO Command received in Invalid state.

Now we can pull messages, changes flags, and copy them succesfully - but the problem happens when we CommitDeletes. Can you please provide some guidance?

Thank you!

Hi Joseph,

Thank you for writing to Aspose Support team.

We have tested this issue at our end by deleting few messages from Office 365 test account and were not able to face any such problem as you have specified. The message is deleted without any such error raised. Could you please try it with the following test account by sending some test messages first and let us know your feedback?

Username: UserTwo@AsposeJul2016.onmicrosoft.com

Password: Aspose1234

Did you test using IMAP credentials?

I used your account, read the message from the folder called “UFC_Test” and tried to delete it. I received the exact same error.

I’m attaching the properties of the IMAP client for your reference.

Hi Joseph,


Yes, we have tested it with this test account using the IMAP client. Please have a look at the contents of the folder you have mentioned and you will find that the email has been deleted now. We are using the latest version of the API i.e. Aspose.Email for .NET 6.7.0 while testing this issue at our end.

Can you please post the code you are using? Thank you!

Hi,


The code that we are trying at our end is as follow:

Code:

ImapClient client = new ImapClient(“outlook.office365.com”, 993, “usertwo@asposejul2016.onmicrosoft.com”, “Aspose1234”);
client.SecurityOptions = SecurityOptions.Auto;

ImapFolderInfo fi = client.GetFolderInfo(“UFC_TEST”);
client.SelectFolder(fi.Name);

ImapMessageInfoCollection msgsColl = client.ListMessages();

if (msgsColl.Count > 0)
{
Console.WriteLine(msgsColl[0].Subject);
client.DeleteMessage(msgsColl[0].UniqueId);

client.CommitDeletes();
}

Ok, after working through your sample, I was able to determine that I need to select the folder AGAIN right before we delete the message.

Here’s my updated code for your reference:

For Each _ImapMessage In _ImapMessageInfoCollection

_AsposeImapClient.ChangeMessageFlags(_ImapMessage.UniqueId, Aspose.Email.Imap.ImapMessageFlags.IsRead)

_AsposeImapClient.CopyMessage(_ImapMessage.UniqueId, strMoveToFolderName)

'version 6.7.0.0 of Aspose required that we select the folder
_AsposeImapClient.SelectFolder(objMailbox.MailboxName)
_AsposeImapClient.DeleteMessage(_ImapMessage.UniqueId)

Next

Hi,


We have modified our code to verify your stance but were not able to get success. Could you please have a look at the following code sample and let us your feedback. If the code sample is not inline with your code that gives raise to exception, please change it and share with us so that we can use it to investigate the issue further. Please note that no SelectFolder statement is used this time.

Sample Code:

ImapClient client = new ImapClient(“outlook.office365.com”, 993, “usertwo@asposejul2016.onmicrosoft.com”, “Aspose1234”);
client.SecurityOptions = SecurityOptions.Auto;


ImapFolderInfo fi = client.GetFolderInfo(“UFC_TEST”);
//list messages from inbox
ImapMessageInfoCollection msgsColl = client.ListMessages();

if (msgsColl.Count > 0)
{
Console.WriteLine(msgsColl[0].Subject);

//copy this message to UFC_TEST
client.CopyMessage(msgsColl[0].UniqueId, fi.Name);

client.DeleteMessage(msgsColl[0].UniqueId);

client.CommitDeletes();
}