Delete Message-Wrong Unique Identifier-GMail

I am using POP3Client to retrieve a message and deleting the message using 'UniqueId' retrieved for that message. This works fine with Exchange Server, Office 365 but seems to be an issue with GMail. With Gmail, I get the error 'Wrong Unique Identifier' when trying to delete the message. I have attached my Gmail POP setting for your reference.

Hi Sathyapriya,

Thank you for contacting Aspose support team.

I have tested the following code and no exception is raised while deleting the mail from gmail account.

Pop3Client client = GetPop3Client2();
int iCount = client.GetMessageCount();
Pop3MessageInfoCollection info = client.ListMessages();
foreach (Pop3MessageInfo MsgInfo in info)
    if (MsgInfo.Subject == "Test Email for deletion")
            Console.WriteLine("Message deleted");
        catch (Exception ex)
            Console.WriteLine("Message could not be deleted");

However, the message is not deleted from the Gmail account with the Pop3 settings shared by you. You may please set the Pop3 settings as attached here in order to delete the message from the server.

Sorry for not being clear. I just showed you the GMail POP setting. Please note that I am not using the same POP3 connection to retrieve the message and delete.

These are the steps

1. Connect -> Retrieve the message. Unique ID will be held in a temporary object

2. Other Validations..

3. Connect -> Delete the message using the Unique ID held . I get an error "Wrong Unique Identifier"

Please find the delete message method for your reference.

public bool DeleteMessage(string UniqueId,string Host, int Port, string Username, string Password, bool EnableSSL, out string Error)
Error = "";
try {
Pop3Client client = GetPOP3Client(Host, Port, Username, Password, EnableSSL);
if (client != null)
return true;
return false;
catch (Exception ex)
Error = ex.Message;
return false;

Hi Sathyapriya,

Thank you for sharing additional information.

We have further tested this issue in light of the details you shared with us. Unfortunately, we were still unable to face any exception while testing with the latest version of Aspose.Email for .NET 5.5.0. I have included the sample test code from my test application that includes the main method as well for illustration of the sequence of calls to methods. Could you please confirm to us if you are using the latest version of Aspose.Email for .NET at your end? If the issue still persists, please create a test Gmail account and once you are able to reproduce the issue via it, share its credential and complete sample code with us. We’ll look into it for assisting you further.(uniqueid1 and uniqueid2 are static variables that retain the values retrieved from the messages)

Sample Code:

static void Main(string[] args)




Console.WriteLine("\nExecution completed...");



static void DeleteUsingUniqIds()


Pop3Client client = new Pop3Client("", 995, "username", "password");

client.SecurityOptions = SecurityOptions.Auto;

Console.WriteLine("Deleting " + uniqueId1);


Console.WriteLine("Deleting " + uniqueId2);




static void CheckPop3DeleteIsseu()


Pop3Client client = new Pop3Client("", 995, "username", "password");

client.SecurityOptions = SecurityOptions.Auto;

Pop3MessageInfoCollection msgsColl = client.ListMessages();

uniqueId1 = msgsColl[0].UniqueId;

uniqueId2 = msgsColl[1].UniqueId;

}<!–[if gte mso 9]>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}


Thank you for your reply. As I said earlier, this happens only when the message is retrieved already. When I list the message and delete them, it is fine.

I use fetchmessage(client.fetchmessage(UniqueId)) to retrieve the message on a different connection.

Hi Sathyapriya,

We have tested this issue even with FetchMessage and no exception is raised. For further investigation into this issue, we would request you to please provide us with a sample console application that we can use to replicate this problem at our end. You can leave the username and password fields empty that we would replace with a test account at our end. This will help us reproduce the issue at our end and we shall be able to assist you further.

Attached is the App which retrieves messages and attempts a delete when Receive button is clicked on the 'Receive' tab. I have removed my licence file.

Please include gmail username, password, create a folder similar to (C:\Pop3Attach) , it fails otherwise.

Hi Sathyapriya,

I have checked the attached SecureMailApp.rar and observed that its the exe only and not the sample code. Could you please send us a simplified console application which can be compiled and executed here to re-produce the scenario as requested here.

It will help us to observe the issue and provide assistance as soon as possible.

I have attached the sample console application. It errors with "Wrong Unique Identifier" when a valid UserName/Password is provided.

Hi Sathyapriya,

We could not find any sample code in your attached project and the project is empty as shown in the attached screenshot. We would request you to please share your sample application with us so that we can investigate the issue further for assisting you further.

I have attached the solution again. Please check if it downloads ok.


Hi Sathyapriya,

As per the RFC 1939, following are the instructions about unique identifier about a message and this behavior seems to be expected. If you remove the following line from your sample code, the error doesn’t occur any more.


If you delete the same using the Unique Identifier of the message, the message is deleted and no exception is raised. Please try at your end and and share your feedback with us.

RFC 1939:

“The unique-id of a message is an arbitrary server-determined string, […], which uniquely identifies a message within a maildrop and which persists across sessions.”

“The server should never reuse an unique-id in a given maildrop, for as long as theentity using the unique-id exists.”

So in theory if the email is deleted server may reuse the same unique-id.

“While it is generally preferable for server implementations to store arbitrarily assigned unique-ids in the maildrop, this specification is intended to permit unique-ids to be calculated as a hash of the message.

Clients should be able to handle a situation where two identical copies of a message in a maildrop have the same unique-id.”

Thank you for the details. I am not getting an exception this time but I still see that the message is not deleted. I set the below property under 'Gmail- Forwarding and POP/IMAP' setting
2. When messages are accessed with POP = 'mark Gmail's copy as read.' I would like the message to be deleted on call of deletemessage(uniqueid), commitdeletes() when this property is set.

When I set it to 'Delete Gmail's copy', the message gets deleted before calling the delete message and it is not the deletemessage(uniqueid) that is actually deleting it. Please could you try setting the POP settings of your test gmail account to 'mark Gmail's copy as read' and confirm this works ok. Thanks.

Hi Sathyapriya,

This is an expected behavior from Gmail server that doesn’t allow deleting emails if “mark Gmail’s copy as read” is selected in settings. Aspose.Email API can’t help in this as we have confirmed from our end and using 3rd party tools as well.