Pop3Client Class

A POP3 client that can be used to retrieve messages from a server.

Definition

Namespace: MailKit.Net.Pop3
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public class Pop3Client : MailSpool, IPop3Client, 
	IMailSpool, IMailService, IDisposable, IAsyncDisposable, IEnumerable<MimeMessage>, 
	IEnumerable
Inheritance
Object    MailService    MailSpool    Pop3Client
Implements
IMailService, IMailSpool, IPop3Client, IEnumerableMimeMessage, IEnumerable, IAsyncDisposable, IDisposable

Remarks

The Pop3Client class supports both the "pop" and "pops" protocols. The "pop" protocol makes a clear-text connection to the POP3 server and does not use SSL or TLS unless the POP3 server supports the STLS extension. The "pops" protocol, however, connects to the POP3 server using an SSL-wrapped connection.

Example

C#
                    public static void DownloadMessages ()
{
    using (var client = new Pop3Client ()) {
        client.Connect ("pop.gmail.com", 995, SecureSocketOptions.SslOnConnect);

        client.Authenticate ("username", "password");

        for (int i = 0; i < client.Count; i++) {
            var message = client.GetMessage (i);

            // write the message to a file
            message.WriteTo (string.Format ("{0}.eml", i));

            // mark the message for deletion
            client.DeleteMessage (i);
        }

        client.Disconnect (true);
    }
}
                  

Constructors

Pop3Client Initializes a new instance of the Pop3Client class.
Pop3Client(IProtocolLogger) Initializes a new instance of the Pop3Client class.

Properties

AuthenticationMechanisms Gets the authentication mechanisms supported by the POP3 server.
(Overrides MailServiceAuthenticationMechanisms)
Capabilities Gets the capabilities supported by the POP3 server.
CheckCertificateRevocation Get or set whether connecting via SSL/TLS should check certificate revocation.
(Inherited from MailService)
ClientCertificates Get or set the client SSL certificates.
(Inherited from MailService)
Count Get the number of messages available in the message spool.
(Overrides MailSpoolCount)
ExpirePolicy Gets the expiration policy.
Implementation Gets the implementation details of the server.
IsAuthenticated Get whether or not the client is currently authenticated with the POP3 server.
(Overrides MailServiceIsAuthenticated)
IsConnected Gets whether or not the client is currently connected to an POP3 server.
(Overrides MailServiceIsConnected)
IsEncrypted Get whether or not the connection is encrypted (typically via SSL or TLS).
(Overrides MailServiceIsEncrypted)
IsSecure Get whether or not the connection is secure (typically via SSL or TLS).
(Overrides MailServiceIsSecure)
IsSigned Get whether or not the connection is signed (typically via SSL or TLS).
(Overrides MailServiceIsSigned)
LocalEndPoint Get or set the local IP end point to use when connecting to the remote host.
(Inherited from MailService)
LoginDelay Gets the minimum delay, in milliseconds, between logins.
Protocol Gets the protocol supported by the message service.
(Overrides MailServiceProtocol)
ProtocolLogger Get the protocol logger.
(Inherited from MailService)
ProxyClient Get or set the proxy client to use when connecting to a remote host.
(Inherited from MailService)
ServerCertificateValidationCallback Get or set a callback function to validate the server certificate.
(Inherited from MailService)
Size Get the size of the POP3 mailbox, in bytes.
SslCipherSuite Get the negotiated SSL or TLS cipher suite.
(Overrides MailServiceSslCipherSuite)
SslCipherSuitesPolicy Get or set the cipher suites allowed to be used when negotiating an SSL or TLS connection.
(Inherited from MailService)
SslProtocol Get the negotiated SSL or TLS protocol version.
(Overrides MailServiceSslProtocol)
SslProtocols Get or set the set of enabled SSL and/or TLS protocol versions that the client is allowed to use.
(Inherited from MailService)
SupportsUids Gets whether or not the Pop3Client supports referencing messages by UIDs.
(Overrides MailSpoolSupportsUids)
SyncRoot Gets an object that can be used to synchronize access to the POP3 server.
(Overrides MailServiceSyncRoot)
Timeout Gets or sets the timeout for network streaming operations, in milliseconds.
(Overrides MailServiceTimeout)

Methods

Authenticate(ICredentials, CancellationToken) Authenticate using the supplied credentials.
(Inherited from MailService)
Authenticate(SaslMechanism, CancellationToken) Authenticate using the specified SASL mechanism.
(Overrides MailServiceAuthenticate(SaslMechanism, CancellationToken))
Authenticate(Encoding, ICredentials, CancellationToken) Authenticate using the supplied credentials.
(Overrides MailServiceAuthenticate(Encoding, ICredentials, CancellationToken))
Authenticate(String, String, CancellationToken) Authenticate using the specified user name and password.
(Inherited from MailService)
Authenticate(Encoding, String, String, CancellationToken) Authenticate using the specified user name and password.
(Inherited from MailService)
AuthenticateAsync(ICredentials, CancellationToken) Asynchronously authenticate using the supplied credentials.
(Inherited from MailService)
AuthenticateAsync(SaslMechanism, CancellationToken) Asynchronously authenticate using the specified SASL mechanism.
(Overrides MailServiceAuthenticateAsync(SaslMechanism, CancellationToken))
AuthenticateAsync(Encoding, ICredentials, CancellationToken) Asynchronously authenticates using the supplied credentials.
(Overrides MailServiceAuthenticateAsync(Encoding, ICredentials, CancellationToken))
AuthenticateAsync(String, String, CancellationToken) Asynchronously authenticate using the specified user name and password.
(Inherited from MailService)
AuthenticateAsync(Encoding, String, String, CancellationToken) Asynchronously authenticate using the specified user name and password.
(Inherited from MailService)
Connect(Uri, CancellationToken) Establish a connection to the specified mail server.
(Inherited from MailService)
Connect(String, Int32, Boolean, CancellationToken) Establish a connection to the specified mail server.
(Inherited from MailService)
Connect(String, Int32, SecureSocketOptions, CancellationToken) Establish a connection to the specified POP3 or POP3/S server.
(Overrides MailServiceConnect(String, Int32, SecureSocketOptions, CancellationToken))
Connect(Socket, String, Int32, SecureSocketOptions, CancellationToken) Establish a connection to the specified POP3 or POP3/S server using the provided socket.
(Overrides MailServiceConnect(Socket, String, Int32, SecureSocketOptions, CancellationToken))
Connect(Stream, String, Int32, SecureSocketOptions, CancellationToken) Establish a connection to the specified POP3 or POP3/S server using the provided stream.
(Overrides MailServiceConnect(Stream, String, Int32, SecureSocketOptions, CancellationToken))
ConnectAsync(Uri, CancellationToken) Asynchronously establish a connection to the specified mail server.
(Inherited from MailService)
ConnectAsync(String, Int32, Boolean, CancellationToken) Asynchronously establish a connection to the specified mail server.
(Inherited from MailService)
ConnectAsync(String, Int32, SecureSocketOptions, CancellationToken) Asynchronously establish a connection to the specified POP3 or POP3/S server.
(Overrides MailServiceConnectAsync(String, Int32, SecureSocketOptions, CancellationToken))
ConnectAsync(Socket, String, Int32, SecureSocketOptions, CancellationToken) Asynchronously establish a connection to the specified POP3 or POP3/S server using the provided socket.
(Overrides MailServiceConnectAsync(Socket, String, Int32, SecureSocketOptions, CancellationToken))
ConnectAsync(Stream, String, Int32, SecureSocketOptions, CancellationToken) Asynchronously establish a connection to the specified POP3 or POP3/S server using the provided stream.
(Overrides MailServiceConnectAsync(Stream, String, Int32, SecureSocketOptions, CancellationToken))
DeleteAllMessages Mark all messages for deletion.
(Overrides MailSpoolDeleteAllMessages(CancellationToken))
DeleteAllMessagesAsync Asynchronously mark all messages for deletion.
(Overrides MailSpoolDeleteAllMessagesAsync(CancellationToken))
DeleteMessage Mark the specified message for deletion.
(Overrides MailSpoolDeleteMessage(Int32, CancellationToken))
DeleteMessageAsync Asynchronously mark the specified message for deletion.
(Overrides MailSpoolDeleteMessageAsync(Int32, CancellationToken))
DeleteMessages(IListInt32, CancellationToken) Mark the specified messages for deletion.
(Overrides MailSpoolDeleteMessages(IListInt32, CancellationToken))
DeleteMessages(Int32, Int32, CancellationToken) Mark the specified range of messages for deletion.
(Overrides MailSpoolDeleteMessages(Int32, Int32, CancellationToken))
DeleteMessagesAsync(IListInt32, CancellationToken) Asynchronously mark the specified messages for deletion.
(Overrides MailSpoolDeleteMessagesAsync(IListInt32, CancellationToken))
DeleteMessagesAsync(Int32, Int32, CancellationToken) Asynchronously mark the specified range of messages for deletion.
(Overrides MailSpoolDeleteMessagesAsync(Int32, Int32, CancellationToken))
Disconnect Disconnect the service.
(Overrides MailServiceDisconnect(Boolean, CancellationToken))
DisconnectAsync Asynchronously disconnect the service.
(Overrides MailServiceDisconnectAsync(Boolean, CancellationToken))
Dispose Releases all resource used by the MailService object.
(Inherited from MailService)
Dispose(Boolean) Releases the unmanaged resources used by the Pop3Client and optionally releases the managed resources.
(Overrides MailServiceDispose(Boolean))
DisposeAsync Asynchronously releases all resources used by the MailService object.
(Inherited from MailService)
DisposeAsyncCore Asynchronously releases the managed resources used by the MailService.
(Inherited from MailService)
EnableUTF8 Enable UTF8 mode.
EnableUTF8Async Asynchronously enable UTF8 mode.
Equals Determines whether the specified object is equal to the current object.
(Inherited from Object)
Finalize Releases unmanaged resources and performs other cleanup operations before the MailService is reclaimed by garbage collection.
(Inherited from MailService)
GetEnumerator Get an enumerator for the messages in the folder.
(Overrides MailSpoolGetEnumerator)
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetLanguages Get the list of languages supported by the POP3 server.
GetLanguagesAsync Asynchronously get the list of languages supported by the POP3 server.
GetMessage Get the message at the specified index.
(Overrides MailSpoolGetMessage(Int32, CancellationToken, ITransferProgress))
GetMessageAsync Asynchronously get the message at the specified index.
(Overrides MailSpoolGetMessageAsync(Int32, CancellationToken, ITransferProgress))
GetMessageCount Get the message count.
(Overrides MailSpoolGetMessageCount(CancellationToken))
GetMessageCountAsync Asynchronously get the message count.
(Overrides MailSpoolGetMessageCountAsync(CancellationToken))
GetMessageHeaders(IListInt32, CancellationToken) Get the headers for the messages at the specified indexes.
(Overrides MailSpoolGetMessageHeaders(IListInt32, CancellationToken))
GetMessageHeaders(Int32, CancellationToken) Get the headers for the message at the specified index.
(Overrides MailSpoolGetMessageHeaders(Int32, CancellationToken))
GetMessageHeaders(Int32, Int32, CancellationToken) Get the headers of the messages within the specified range.
(Overrides MailSpoolGetMessageHeaders(Int32, Int32, CancellationToken))
GetMessageHeadersAsync(IListInt32, CancellationToken) Asynchronously get the headers for the messages at the specified indexes.
(Overrides MailSpoolGetMessageHeadersAsync(IListInt32, CancellationToken))
GetMessageHeadersAsync(Int32, CancellationToken) Asynchronously get the headers for the message at the specified index.
(Overrides MailSpoolGetMessageHeadersAsync(Int32, CancellationToken))
GetMessageHeadersAsync(Int32, Int32, CancellationToken) Asynchronously get the headers of the messages within the specified range.
(Overrides MailSpoolGetMessageHeadersAsync(Int32, Int32, CancellationToken))
GetMessages(IListInt32, CancellationToken, ITransferProgress) Get the messages at the specified indexes.
(Overrides MailSpoolGetMessages(IListInt32, CancellationToken, ITransferProgress))
GetMessages(Int32, Int32, CancellationToken, ITransferProgress) Get the messages within the specified range.
(Overrides MailSpoolGetMessages(Int32, Int32, CancellationToken, ITransferProgress))
GetMessagesAsync(IListInt32, CancellationToken, ITransferProgress) Asynchronously get the messages at the specified indexes.
(Overrides MailSpoolGetMessagesAsync(IListInt32, CancellationToken, ITransferProgress))
GetMessagesAsync(Int32, Int32, CancellationToken, ITransferProgress) Asynchronously get the messages within the specified range.
(Overrides MailSpoolGetMessagesAsync(Int32, Int32, CancellationToken, ITransferProgress))
GetMessageSize Get the size of the specified message, in bytes.
(Overrides MailSpoolGetMessageSize(Int32, CancellationToken))
GetMessageSizeAsync Asynchronously get the size of the specified message, in bytes.
(Overrides MailSpoolGetMessageSizeAsync(Int32, CancellationToken))
GetMessageSizes Get the sizes for all available messages, in bytes.
(Overrides MailSpoolGetMessageSizes(CancellationToken))
GetMessageSizesAsync Asynchronously get the sizes for all available messages, in bytes.
(Overrides MailSpoolGetMessageSizesAsync(CancellationToken))
GetMessageUid Get the UID of the message at the specified index.
(Overrides MailSpoolGetMessageUid(Int32, CancellationToken))
GetMessageUidAsync Asynchronously get the UID of the message at the specified index.
(Overrides MailSpoolGetMessageUidAsync(Int32, CancellationToken))
GetMessageUids Get the full list of available message UIDs.
(Overrides MailSpoolGetMessageUids(CancellationToken))
GetMessageUidsAsync Asynchronously get the full list of available message UIDs.
(Overrides MailSpoolGetMessageUidsAsync(CancellationToken))
GetSslClientAuthenticationOptions Gets the SSL/TLS client authentication options for use with .NET5's SslStream.AuthenticateAsClient() API.
(Inherited from MailService)
GetStream Get the message or header stream at the specified index.
(Overrides MailSpoolGetStream(Int32, Boolean, CancellationToken, ITransferProgress))
GetStreamAsync Asynchronously get the message or header stream at the specified index.
(Overrides MailSpoolGetStreamAsync(Int32, Boolean, CancellationToken, ITransferProgress))
GetStreams(IListInt32, Boolean, CancellationToken, ITransferProgress) Get the message or header streams at the specified indexes.
(Overrides MailSpoolGetStreams(IListInt32, Boolean, CancellationToken, ITransferProgress))
GetStreams(Int32, Int32, Boolean, CancellationToken, ITransferProgress) Get the message or header streams within the specified range.
(Overrides MailSpoolGetStreams(Int32, Int32, Boolean, CancellationToken, ITransferProgress))
GetStreamsAsync(IListInt32, Boolean, CancellationToken, ITransferProgress) Asynchronously get the message or header streams at the specified indexes.
(Overrides MailSpoolGetStreamsAsync(IListInt32, Boolean, CancellationToken, ITransferProgress))
GetStreamsAsync(Int32, Int32, Boolean, CancellationToken, ITransferProgress) Asynchronously get the message or header streams within the specified range.
(Overrides MailSpoolGetStreamsAsync(Int32, Int32, Boolean, CancellationToken, ITransferProgress))
GetType Gets the Type of the current instance.
(Inherited from Object)
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
NoOp Ping the POP3 server to keep the connection alive.
(Overrides MailServiceNoOp(CancellationToken))
NoOpAsync Ping the POP3 server to keep the connection alive.
(Overrides MailServiceNoOpAsync(CancellationToken))
OnAuthenticated Raise the authenticated event.
(Inherited from MailService)
OnConnected Raise the connected event.
(Inherited from MailService)
OnDisconnected Raise the disconnected event.
(Inherited from MailService)
Reset Reset the state of all messages marked for deletion.
(Overrides MailSpoolReset(CancellationToken))
ResetAsync Asynchronously reset the state of all messages marked for deletion.
(Overrides MailSpoolResetAsync(CancellationToken))
SetLanguage Set the language used by the POP3 server for error messages.
SetLanguageAsync Asynchronously set the language used by the POP3 server for error messages.
ToString Returns a string that represents the current object.
(Inherited from Object)

Events

Authenticated Occurs when the client has been successfully authenticated.
(Inherited from MailService)
Connected Occurs when the client has been successfully connected.
(Inherited from MailService)
Disconnected Occurs when the client gets disconnected.
(Inherited from MailService)

See Also