ImapClient Class

An IMAP client that can be used to retrieve messages from a server.

Definition

Namespace: MailKit.Net.Imap
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public class ImapClient : MailStore, IImapClient, 
	IMailStore, IMailService, IDisposable, IAsyncDisposable
Inheritance
Object    MailService    MailStore    ImapClient
Implements
IMailService, IMailStore, IImapClient, IAsyncDisposable, IDisposable

Remarks

The ImapClient class supports both the "imap" and "imaps" protocols. The "imap" protocol makes a clear-text connection to the IMAP server and does not use SSL or TLS unless the IMAP server supports the STARTTLS extension. The "imaps" protocol, however, connects to the IMAP server using an SSL-wrapped connection.

Example

C#
                    public static void DownloadMessages ()
{
    using (var client = new ImapClient ()) {
        client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect);

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

        client.Inbox.Open (FolderAccess.ReadOnly);

        var uids = client.Inbox.Search (SearchQuery.All);

        foreach (var uid in uids) {
            var message = client.Inbox.GetMessage (uid);

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

        client.Disconnect (true);
    }
}
                  

Constructors

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

Properties

AppendLimit Get the maximum size of a message that can be appended to a folder.
AuthenticationMechanisms Get the authentication mechanisms supported by the IMAP server.
(Overrides MailServiceAuthenticationMechanisms)
Capabilities Get the capabilities supported by the IMAP 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)
Inbox Get the Inbox folder.
(Overrides MailStoreInbox)
InternationalizationLevel Get the internationalization level supported by the IMAP server.
IsAuthenticated Get whether or not the client is currently authenticated with the IMAP server.
(Overrides MailServiceIsAuthenticated)
IsConnected Get whether or not the client is currently connected to an IMAP server.
(Overrides MailServiceIsConnected)
IsEncrypted Get whether or not the connection is encrypted (typically via SSL or TLS).
(Overrides MailServiceIsEncrypted)
IsIdle Get whether or not the client is currently in the IDLE state.
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)
OtherNamespaces Get the other namespaces.
(Overrides MailStoreOtherNamespaces)
PersonalNamespaces Get the personal namespaces.
(Overrides MailStorePersonalNamespaces)
Protocol Get 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)
Rights Get the access rights supported by the IMAP server.
ServerCertificateValidationCallback Get or set a callback function to validate the server certificate.
(Inherited from MailService)
SharedNamespaces Get the shared namespaces.
(Overrides MailStoreSharedNamespaces)
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)
SupportsQuotas Get whether or not the mail store supports quotas.
(Overrides MailStoreSupportsQuotas)
SyncRoot Gets an object that can be used to synchronize access to the IMAP server.
(Overrides MailServiceSyncRoot)
ThreadingAlgorithms Get the threading algorithms supported by the IMAP server.
(Overrides MailStoreThreadingAlgorithms)
Timeout Get or set 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 authenticate 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)
Compress Enable compression over the IMAP connection.
CompressAsync Asynchronously enable compression over the IMAP connection.
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 IMAP server.
(Overrides MailServiceConnect(String, Int32, SecureSocketOptions, CancellationToken))
Connect(Socket, String, Int32, SecureSocketOptions, CancellationToken) Establish a connection to the specified IMAP or IMAP/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 IMAP or IMAP/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 IMAP server.
(Overrides MailServiceConnectAsync(String, Int32, SecureSocketOptions, CancellationToken))
ConnectAsync(Socket, String, Int32, SecureSocketOptions, CancellationToken) Asynchronously establish a connection to the specified IMAP or IMAP/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 IMAP or IMAP/S server using the provided stream.
(Overrides MailServiceConnectAsync(Stream, String, Int32, SecureSocketOptions, CancellationToken))
CreateIdleSession Create a new ImapIdleSession for waiting on changes to the selected folder.
CreateImapFolder Instantiate a new ImapFolder.
DisableNotify Disable any previously requested notification events from the IMAP server.
DisableNotifyAsync Asynchronously disable any previously requested notification events from the IMAP server.
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 ImapClient 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)
Enable Enable the specified IMAP features.
EnableAsync Asynchronously enable the specified IMAP features.
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)
GetFolder(FolderNamespace) Get the folder for the specified namespace.
(Overrides MailStoreGetFolder(FolderNamespace))
GetFolder(SpecialFolder) Get the specified special folder.
(Overrides MailStoreGetFolder(SpecialFolder))
GetFolder(String, CancellationToken) Get the folder for the specified path.
(Overrides MailStoreGetFolder(String, CancellationToken))
GetFolderAsync Asynchronously get the folder for the specified path.
(Overrides MailStoreGetFolderAsync(String, CancellationToken))
GetFolders(FolderNamespace, Boolean, CancellationToken) Get all of the folders within the specified namespace.
(Inherited from MailStore)
GetFolders(FolderNamespace, StatusItems, Boolean, CancellationToken) Get all of the folders within the specified namespace.
(Overrides MailStoreGetFolders(FolderNamespace, StatusItems, Boolean, CancellationToken))
GetFoldersAsync(FolderNamespace, Boolean, CancellationToken) Asynchronously get all of the folders within the specified namespace.
(Inherited from MailStore)
GetFoldersAsync(FolderNamespace, StatusItems, Boolean, CancellationToken) Asynchronously get all of the folders within the specified namespace.
(Overrides MailStoreGetFoldersAsync(FolderNamespace, StatusItems, Boolean, CancellationToken))
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetMetadata(IEnumerableMetadataTag, CancellationToken) Gets the specified metadata.
(Inherited from MailStore)
GetMetadata(MetadataTag, CancellationToken) Gets the specified metadata.
(Overrides MailStoreGetMetadata(MetadataTag, CancellationToken))
GetMetadata(MetadataOptions, IEnumerableMetadataTag, CancellationToken) Gets the specified metadata.
(Overrides MailStoreGetMetadata(MetadataOptions, IEnumerableMetadataTag, CancellationToken))
GetMetadataAsync(IEnumerableMetadataTag, CancellationToken) Asynchronously gets the specified metadata.
(Inherited from MailStore)
GetMetadataAsync(MetadataTag, CancellationToken) Asynchronously gets the specified metadata.
(Overrides MailStoreGetMetadataAsync(MetadataTag, CancellationToken))
GetMetadataAsync(MetadataOptions, IEnumerableMetadataTag, CancellationToken) Asynchronously gets the specified metadata.
(Overrides MailStoreGetMetadataAsync(MetadataOptions, IEnumerableMetadataTag, CancellationToken))
GetSslClientAuthenticationOptions Gets the SSL/TLS client authentication options for use with .NET5's SslStream.AuthenticateAsClient() API.
(Inherited from MailService)
GetType Gets the Type of the current instance.
(Inherited from Object)
Identify Identify the client implementation to the server and obtain the server implementation details.
IdentifyAsync Asynchronously identify the client implementation to the server and obtain the server implementation details.
Idle Toggle the ImapClient into the IDLE state.
IdleAsync Asynchronously toggle the ImapClient into the IDLE state.
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
NoOp Ping the IMAP server to keep the connection alive.
(Overrides MailServiceNoOp(CancellationToken))
NoOpAsync Asynchronously ping the IMAP server to keep the connection alive.
(Overrides MailServiceNoOpAsync(CancellationToken))
Notify Request the specified notification events from the IMAP server.
NotifyAsync Asynchronously request the specified notification events from the IMAP server.
OnAlert Raise the alert event.
(Inherited from MailStore)
OnAuthenticated Raise the authenticated event.
(Inherited from MailService)
OnConnected Raise the connected event.
(Inherited from MailService)
OnDisconnected Raise the disconnected event.
(Inherited from MailService)
OnFolderCreated Raise the folder created event.
(Inherited from MailStore)
OnMetadataChanged Raise the metadata changed event.
(Inherited from MailStore)
OnWebAlert Raise the web alert event.
SetMetadata Sets the specified metadata.
(Overrides MailStoreSetMetadata(MetadataCollection, CancellationToken))
SetMetadataAsync Asynchronously gets the specified metadata.
(Overrides MailStoreSetMetadataAsync(MetadataCollection, CancellationToken))
ToString Returns a string that represents the current object.
(Inherited from Object)

Events

Alert Occurs when a remote message store receives an alert message from the server.
(Inherited from MailStore)
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)
FolderCreated Occurs when a folder is created.
(Inherited from MailStore)
MetadataChanged Occurs when metadata changes.
(Inherited from MailStore)
WebAlert Occurs when a Google Mail server sends a WEBALERT response code to the client.

See Also