Pop |
public override Task<IList<string>> GetMessageUidsAsync( CancellationToken cancellationToken = default )
Exception | Condition |
---|---|
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. |
Gets the full list of available message UIDs.
Caution |
---|
Not all servers support UIDs, so you should first check the Capabilities property for the UIDL flag or the SupportsUids convenience property. |
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.HasFlag (Pop3Capabilities.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}.msg", uids[i])); // add the message uid to our list of downloaded uids previouslyDownloadedUids.Add (uids[i]); } client.Disconnect (true); } }