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")
{
try
{
client.DeleteMessage(MsgInfo.UniqueId);
client.CommitDeletes();
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)
{
client.DeleteMessage(UniqueId);
client.CommitDeletes();
return true;
}
else
{
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)
{
CheckPop3DeleteIsseu();
DeleteUsingUniqIds();
Console.WriteLine("\nExecution completed...");
Console.ReadKey();
}
static void DeleteUsingUniqIds()
{
Pop3Client client = new Pop3Client("pop.gmail.com", 995, "username", "password");
client.SecurityOptions = SecurityOptions.Auto;
Console.WriteLine("Deleting " + uniqueId1);
client.DeleteMessage(uniqueId1);
Console.WriteLine("Deleting " + uniqueId2);
client.DeleteMessage(uniqueId2);
client.CommitDeletes();
}
static void CheckPop3DeleteIsseu()
{
Pop3Client client = new Pop3Client("pop.gmail.com", 995, "username", "password");
client.SecurityOptions = SecurityOptions.Auto;
Pop3MessageInfoCollection msgsColl = client.ListMessages();
uniqueId1 = msgsColl[0].UniqueId;
uniqueId2 = msgsColl[1].UniqueId;
}<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<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”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>
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,
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 attached the sample console application. It errors with "Wrong Unique Identifier" when a valid UserName/Password is provided.
Hi Sathyapriya,
I have attached the solution again. Please check if it downloads ok.
Thanks.
Hi Sathyapriya,
client.Disconnect();
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,