![]() | ImapClient Class |
Namespace: MailKit.Net.Imap
public class ImapClient : MailStore, IImapClient, IMailStore, IMailService, IDisposable
The ImapClient type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | ImapClient |
Initializes a new instance of the ImapClient class.
|
![]() ![]() | ImapClient(IProtocolLogger) |
Initializes a new instance of the ImapClient class.
|
Name | Description | |
---|---|---|
![]() | AppendLimit |
Gets 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 |
Gets or sets the client SSL certificates.
(Inherited from MailService.) |
![]() ![]() | Inbox |
Get the Inbox folder.
(Overrides MailStoreInbox.) |
![]() | InternationalizationLevel |
Gets 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 sets a callback function to validate the server certificate.
(Inherited from MailService.) |
![]() | SharedNamespaces |
Get the shared namespaces.
(Overrides MailStoreSharedNamespaces.) |
![]() ![]() | SslCipherAlgorithm |
Get the negotiated SSL or TLS cipher algorithm.
(Overrides MailServiceSslCipherAlgorithm.) |
![]() ![]() | SslCipherStrength |
Get the negotiated SSL or TLS cipher algorithm strength.
(Overrides MailServiceSslCipherStrength.) |
![]() ![]() | SslHashAlgorithm |
Get the negotiated SSL or TLS hash algorithm.
(Overrides MailServiceSslHashAlgorithm.) |
![]() ![]() | SslHashStrength |
Get the negotiated SSL or TLS hash algorithm strength.
(Overrides MailServiceSslHashStrength.) |
![]() ![]() | SslKeyExchangeAlgorithm |
Get the negotiated SSL or TLS key exchange algorithm.
(Overrides MailServiceSslKeyExchangeAlgorithm.) |
![]() ![]() | SslKeyExchangeStrength |
Get the negotiated SSL or TLS key exchange algorithm strength.
(Overrides MailServiceSslKeyExchangeStrength.) |
![]() ![]() | SslProtocol |
Get the negotiated SSL or TLS protocol version.
(Overrides MailServiceSslProtocol.) |
![]() | SslProtocols |
Gets or sets 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.) |
Name | Description | |
---|---|---|
![]() | 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).) |
![]() | 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).) |
![]() | EnableQuickResync |
Enable the QRESYNC feature.
(Overrides MailStoreEnableQuickResync(CancellationToken).) |
![]() | EnableQuickResyncAsync |
Asynchronously enable the QRESYNC feature.
(Overrides MailStoreEnableQuickResyncAsync(CancellationToken).) |
![]() | EnableUTF8 |
Enable the UTF8=ACCEPT extension.
|
![]() | EnableUTF8Async |
Asynchronously enable the UTF8=ACCEPT extension.
|
![]() | 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).) |
![]() | 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.) |
Name | Description | |
---|---|---|
![]() | 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.
|
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); } }
public static void DownloadBodyParts () { using (var client = new ImapClient ()) { client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect); client.Authenticate ("username", "password"); client.Inbox.Open (FolderAccess.ReadOnly); // search for messages where the Subject header contains either "MimeKit" or "MailKit" var query = SearchQuery.SubjectContains ("MimeKit").Or (SearchQuery.SubjectContains ("MailKit")); var uids = client.Inbox.Search (query); // fetch summary information for the search results (we will want the UID and the BODYSTRUCTURE // of each message so that we can extract the text body and the attachments) var items = client.Inbox.Fetch (uids, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure); foreach (var item in items) { // determine a directory to save stuff in var directory = Path.Combine (baseDirectory, item.UniqueId.ToString ()); // create the directory Directory.CreateDirectory (directory); // IMessageSummary.TextBody is a convenience property that finds the 'text/plain' body part for us var bodyPart = item.TextBody; // download the 'text/plain' body part var body = (TextPart) client.Inbox.GetBodyPart (item.UniqueId, bodyPart); // TextPart.Text is a convenience property that decodes the content and converts the result to // a string for us var text = body.Text; File.WriteAllText (Path.Combine (directory, "body.txt"), text); // now iterate over all of the attachments and save them to disk foreach (var attachment in item.Attachments) { // download the attachment just like we did with the body var entity = client.Inbox.GetBodyPart (item.UniqueId, attachment); // attachments can be either message/rfc822 parts or regular MIME parts if (entity is MessagePart) { var rfc822 = (MessagePart) entity; var path = Path.Combine (directory, attachment.PartSpecifier + ".eml"); rfc822.Message.WriteTo (path); } else { var part = (MimePart) entity; // note: it's possible for this to be null, but most will specify a filename var fileName = part.FileName; var path = Path.Combine (directory, fileName); // decode and save the content to a file using (var stream = File.Create (path)) part.Content.DecodeTo (stream); } } } client.Disconnect (true); } }