Pop 3ClientGet Message Uids Async Method
Asynchronously get the full list of available message UIDs.
Definition
Namespace: MailKit.Net.Pop3
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
The message uids.
IMailSpoolGetMessageUidsAsync(CancellationToken)
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public override Task<IList<string>> GetMessageUidsAsync(
CancellationToken cancellationToken = default
)Parameters
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
TaskIListStringThe message uids.
Implements
IMailSpoolGetMessageUidsAsync(CancellationToken)IMailSpoolGetMessageUidsAsync(CancellationToken)
Remarks
Gets the full list of available message UIDs.
Example
C#
public static void DownloadNewMessages (HashSet<string> previouslyDownloadedUids)
{
using (var client = new Pop3Client ()) {
client.Connect ("pop.gmail.com", 995, SecureSocketOptions.SslOnConnect);
client.Authenticate ("username", "password");
if (!client.Capabilities.Contains (Pop3Capability.UIDL))
throw new Exception ("The POP3 server does not support UIDs!");
var uids = client.GetMessageUids ();
for (int i = 0; i < client.Count; i++) {
// check that we haven't already downloaded this message
// in a previous session
if (previouslyDownloadedUids.Contains (uids[i]))
continue;
var message = client.GetMessage (i);
// write the message to a file
message.WriteTo (string.Format ("{0}.eml", uids[i]));
// add the message uid to our list of downloaded uids
previouslyDownloadedUids.Add (uids[i]);
}
client.Disconnect (true);
}
}
Exceptions
| ObjectDisposedException | The Pop3Client has been disposed. |
| ServiceNotConnectedException | The Pop3Client is not connected. |
| ServiceNotAuthenticatedException | The Pop3Client is not authenticated. |
| NotSupportedException | The POP3 server does not support the UIDL extension. |
| OperationCanceledException | The operation was canceled via the cancellation token. |
| IOException | An I/O error occurred. |
| Pop3CommandException | The POP3 command failed. |
| Pop3ProtocolException | A POP3 protocol error occurred. |