C# Класс MailKit.Net.Imap.ImapClient

An IMAP client that can be used to retrieve messages from a server.
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 (as defined by rfc3501). The "imaps" protocol, however, connects to the IMAP server using an SSL-wrapped connection.
Наследование: IMessageStore
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Authenticate ( Portable.Text.Encoding encoding, ICredentials credentials, CancellationToken cancellationToken = default(CancellationToken) ) : void

Authenticate using the supplied credentials.

If the IMAP server supports one or more SASL authentication mechanisms, then the SASL mechanisms that both the client and server support are tried in order of greatest security to weakest security. Once a SASL authentication mechanism is found that both client and server support, the credentials are used to authenticate.

If the server does not support SASL or if no common SASL mechanisms can be found, then LOGIN command is used as a fallback.

To prevent the usage of certain authentication mechanisms, simply remove them from the AuthenticationMechanisms hash set before calling this method.
Compress ( CancellationToken cancellationToken = default(CancellationToken) ) : void

Enable compression over the IMAP connection.

Enables compression over the IMAP connection.

If the IMAP server supports the ImapCapabilities.Compress extension, it is possible at any point after connecting to enable compression to reduce network bandwidth usage. Ideally, this method should be called before authenticating.

CompressAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task

Asynchronously enable compression over the IMAP connection.

Asynchronously enables compression over the IMAP connection.

If the IMAP server supports the ImapCapabilities.Compress extension, it is possible at any point after connecting to enable compression to reduce network bandwidth usage. Ideally, this method should be called before authenticating.

Connect ( Socket socket, string host, int port, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default(CancellationToken) ) : void

Establish a connection to the specified IMAP or IMAP/S server using the provided socket.

Establishes a connection to the specified IMAP or IMAP/S server using the provided socket.

If the port has a value of 0, then the options parameter is used to determine the default port to connect to. The default port used with SecureSocketOptions.SslOnConnect is 993. All other values will use a default port of 143.

If the options has a value of SecureSocketOptions.Auto, then the port is used to determine the default security options. If the port has a value of 993, then the default options used will be SecureSocketOptions.SslOnConnect. All other values will use SecureSocketOptions.StartTlsWhenAvailable.

Once a connection is established, properties such as AuthenticationMechanisms and Capabilities will be populated.

Connect ( string host, int port, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default(CancellationToken) ) : void

Establish a connection to the specified IMAP server.

Establishes a connection to the specified IMAP or IMAP/S server.

If the port has a value of 0, then the options parameter is used to determine the default port to connect to. The default port used with SecureSocketOptions.SslOnConnect is 993. All other values will use a default port of 143.

If the options has a value of SecureSocketOptions.Auto, then the port is used to determine the default security options. If the port has a value of 993, then the default options used will be SecureSocketOptions.SslOnConnect. All other values will use SecureSocketOptions.StartTlsWhenAvailable.

Once a connection is established, properties such as AuthenticationMechanisms and Capabilities will be populated.

Disconnect ( bool quit, CancellationToken cancellationToken = default(CancellationToken) ) : void

Disconnect the service.

If quit is true, a LOGOUT command will be issued in order to disconnect cleanly.

EnableQuickResync ( CancellationToken cancellationToken = default(CancellationToken) ) : void

Enable the QRESYNC feature.

Enables the QRESYNC feature.

The QRESYNC extension improves resynchronization performance of folders by querying the IMAP server for a list of changes when the folder is opened using the ImapFolder.Open(FolderAccess,uint,ulong,System.Collections.Generic.IList<UniqueId>,System.Threading.CancellationToken) method.

If this feature is enabled, the MailFolder.MessageExpunged event is replaced with the MailFolder.MessagesVanished event.

This method needs to be called immediately after calling one of the Authenticate methods, before opening any folders.

EnableUTF8 ( CancellationToken cancellationToken = default(CancellationToken) ) : void

Enable the UTF8=ACCEPT extension.

Enables the UTF8=ACCEPT extension.

EnableUTF8Async ( CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task

Enable the UTF8=ACCEPT extension.

Enables the UTF8=ACCEPT extension.

GetFolder ( FolderNamespace @namespace ) : IMailFolder

Get the folder for the specified namespace.

Gets the folder for the specified namespace.

GetFolder ( SpecialFolder folder ) : IMailFolder

Get the specified special folder.

Not all IMAP servers support special folders. Only IMAP servers supporting the ImapCapabilities.SpecialUse or ImapCapabilities.XList extensions may have special folders.

GetFolder ( string path, CancellationToken cancellationToken = default(CancellationToken) ) : IMailFolder

Get the folder for the specified path.

Gets the folder for the specified path.

GetFolders ( FolderNamespace @namespace, StatusItems items = StatusItems.None, bool subscribedOnly = false, CancellationToken cancellationToken = default(CancellationToken) ) : IList

Get all of the folders within the specified namespace.

Gets all of the folders within the specified namespace.

GetMetadata ( MetadataOptions options, IEnumerable tags, CancellationToken cancellationToken = default(CancellationToken) ) : MetadataCollection

Gets the specified metadata.

Gets the specified metadata.

GetMetadata ( MetadataTag tag, CancellationToken cancellationToken = default(CancellationToken) ) : string

Gets the specified metadata.

Gets the specified metadata.

Identify ( MailKit.Net.Imap.ImapImplementation clientImplementation, CancellationToken cancellationToken = default(CancellationToken) ) : MailKit.Net.Imap.ImapImplementation

Identify the client implementation to the server and obtain the server implementation details.

Passes along the client implementation details to the server while also obtaining implementation details from the server.

If the clientImplementation is null or no properties have been set, no identifying information will be sent to the server.

Security Implications

This command has the danger of violating the privacy of users if misused. Clients should notify users that they send the ID command.

It is highly desirable that implementations provide a method of disabling ID support, perhaps by not calling this method at all, or by passing null as the clientImplementation argument.

Implementors must exercise extreme care in adding properties to the clientImplementation. Some properties, such as a processor ID number, Ethernet address, or other unique (or mostly unique) identifier would allow tracking of users in ways that violate user privacy expectations and may also make it easier for attackers to exploit security holes in the client.

IdentifyAsync ( MailKit.Net.Imap.ImapImplementation clientImplementation, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Asynchronously identify the client implementation to the server and obtain the server implementation details.

Passes along the client implementation details to the server while also obtaining implementation details from the server.

If the clientImplementation is null or no properties have been set, no identifying information will be sent to the server.

Security Implications

This command has the danger of violating the privacy of users if misused. Clients should notify users that they send the ID command.

It is highly desirable that implementations provide a method of disabling ID support, perhaps by not calling this method at all, or by passing null as the clientImplementation argument.

Implementors must exercise extreme care in adding properties to the clientImplementation. Some properties, such as a processor ID number, Ethernet address, or other unique (or mostly unique) identifier would allow tracking of users in ways that violate user privacy expectations and may also make it easier for attackers to exploit security holes in the client.

Idle ( CancellationToken doneToken, CancellationToken cancellationToken = default(CancellationToken) ) : void

Toggle the ImapClient into the IDLE state.

When a client enters the IDLE state, the IMAP server will send events to the client as they occur on the selected folder. These events may include notifications of new messages arriving, expunge notifications, flag changes, etc.

Due to the nature of the IDLE command, a folder must be selected before a client can enter into the IDLE state. This can be done by opening a folder using MailKit.MailFolder.Open(FolderAccess,System.Threading.CancellationToken) or any of the other variants.

While the IDLE command is running, no other commands may be issued until the doneToken is cancelled.

It is especially important to cancel the doneToken before cancelling the cancellationToken when using SSL or TLS due to the fact that System.Net.Security.SslStream cannot be polled.
IdleAsync ( CancellationToken doneToken, CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task

Asynchronously toggle the ImapClient into the IDLE state.

When a client enters the IDLE state, the IMAP server will send events to the client as they occur on the selected folder. These events may include notifications of new messages arriving, expunge notifications, flag changes, etc.

Due to the nature of the IDLE command, a folder must be selected before a client can enter into the IDLE state. This can be done by opening a folder using MailKit.MailFolder.Open(FolderAccess,System.Threading.CancellationToken) or any of the other variants.

While the IDLE command is running, no other commands may be issued until the doneToken is cancelled.

It is especially important to cancel the doneToken before cancelling the cancellationToken when using SSL or TLS due to the fact that System.Net.Security.SslStream cannot be polled.
ImapClient ( ) : System

Initializes a new instance of the MailKit.Net.Imap.ImapClient class.

Before you can retrieve messages with the ImapClient, you must first call one of the Connect methods and then authenticate with the one of the Authenticate methods.

ImapClient ( IProtocolLogger protocolLogger ) : System

Initializes a new instance of the MailKit.Net.Imap.ImapClient class.

Before you can retrieve messages with the ImapClient, you must first call one of the Connect methods and then authenticate with the one of the Authenticate methods.

NoOp ( CancellationToken cancellationToken = default(CancellationToken) ) : void

Ping the IMAP server to keep the connection alive.

The NOOP command is typically used to keep the connection with the IMAP server alive. When a client goes too long (typically 30 minutes) without sending any commands to the IMAP server, the IMAP server will close the connection with the client, forcing the client to reconnect before it can send any more commands.

The NOOP command also provides a great way for a client to check for new messages.

When the IMAP server receives a NOOP command, it will reply to the client with a list of pending updates such as EXISTS and RECENT counts on the currently selected folder. To receive these notifications, subscribe to the MailFolder.CountChanged and MailFolder.RecentChanged events, respectively.

For more information about the NOOP command, see rfc3501.

Reconnect ( string password, CancellationToken cancellationToken = default(CancellationToken) ) : void

Reconnect to the most recently connected IMAP server.

Reconnects to the most recently connected IMAP server. Once a successful connection is made, the session will then be re-authenticated using the account name used in the previous session and the password.

ReconnectAsync ( string password, CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task

Asynchronously reconnect to the most recently connected IMAP server.

Asynchronously reconnects to the most recently connected IMAP server. Once a successful connection is made, the session will then be re-authenticated using the account name used in the previous session and the password.

SetMetadata ( MetadataCollection metadata, CancellationToken cancellationToken = default(CancellationToken) ) : void

Sets the specified metadata.

Sets the specified metadata.

Защищенные методы

Метод Описание
CreateImapFolder ( MailKit.Net.Imap.ImapFolderConstructorArgs args ) : ImapFolder

Instantiate a new ImapFolder.

Creates a new ImapFolder instance.

This method's purpose is to allow subclassing ImapFolder.
Dispose ( bool disposing ) : void

Releases the unmanaged resources used by the ImapClient and optionally releases the managed resources.

Releases the unmanaged resources used by the ImapClient and optionally releases the managed resources.

Приватные методы

Метод Описание
CheckAuthenticated ( ) : void
CheckConnected ( ) : void
CheckDisposed ( ) : void
ComputeDefaultValues ( string host, int &port, SecureSocketOptions &options, Uri &uri, bool &starttls ) : void
CreateAuthenticationException ( ImapCommand ic ) : MailKit.Security.AuthenticationException
EscapeUserName ( string userName ) : string
GetSessionIdentifier ( string userName ) : string
HexEscape ( char c ) : string
HexUnescape ( string pattern, int &index ) : char
IdleComplete ( object state ) : void
IsHexDigit ( char c ) : bool
OnEngineAlert ( object sender, AlertEventArgs e ) : void
OnEngineDisconnected ( object sender, EventArgs e ) : void
ProcessResponseCodes ( ImapCommand ic ) : void
ReplayConnect ( string host, Stream replayStream, CancellationToken cancellationToken = default(CancellationToken) ) : void
UnescapeUserName ( string escaped ) : string
ValidateRemoteCertificate ( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors ) : bool

Описание методов

Authenticate() публичный Метод

Authenticate using the supplied credentials.

If the IMAP server supports one or more SASL authentication mechanisms, then the SASL mechanisms that both the client and server support are tried in order of greatest security to weakest security. Once a SASL authentication mechanism is found that both client and server support, the credentials are used to authenticate.

If the server does not support SASL or if no common SASL mechanisms can be found, then LOGIN command is used as a fallback.

To prevent the usage of certain authentication mechanisms, simply remove them from the AuthenticationMechanisms hash set before calling this method.
/// is null. /// -or- /// is null. /// /// The has been disposed. /// /// The is not connected. /// /// The is already authenticated. /// /// The operation was canceled via the cancellation token. /// /// Authentication using the supplied credentials has failed. /// /// A SASL authentication error occurred. /// /// An I/O error occurred. /// /// An IMAP protocol error occurred. ///
public Authenticate ( Portable.Text.Encoding encoding, ICredentials credentials, CancellationToken cancellationToken = default(CancellationToken) ) : void
encoding Portable.Text.Encoding The text encoding to use for the user's credentials.
credentials ICredentials The user's credentials.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

Compress() публичный Метод

Enable compression over the IMAP connection.

Enables compression over the IMAP connection.

If the IMAP server supports the ImapCapabilities.Compress extension, it is possible at any point after connecting to enable compression to reduce network bandwidth usage. Ideally, this method should be called before authenticating.

/// The has been disposed. /// /// The is not connected. /// /// Compression must be enabled before a folder has been selected. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the COMPRESS command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public Compress ( CancellationToken cancellationToken = default(CancellationToken) ) : void
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

CompressAsync() публичный Метод

Asynchronously enable compression over the IMAP connection.

Asynchronously enables compression over the IMAP connection.

If the IMAP server supports the ImapCapabilities.Compress extension, it is possible at any point after connecting to enable compression to reduce network bandwidth usage. Ideally, this method should be called before authenticating.

/// The has been disposed. /// /// The is not connected. /// /// Compression must be enabled before a folder has been selected. /// /// The IMAP server does not support the COMPRESS extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the COMPRESS command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public CompressAsync ( CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат System.Threading.Task

Connect() публичный Метод

Establish a connection to the specified IMAP or IMAP/S server using the provided socket.

Establishes a connection to the specified IMAP or IMAP/S server using the provided socket.

If the port has a value of 0, then the options parameter is used to determine the default port to connect to. The default port used with SecureSocketOptions.SslOnConnect is 993. All other values will use a default port of 143.

If the options has a value of SecureSocketOptions.Auto, then the port is used to determine the default security options. If the port has a value of 993, then the default options used will be SecureSocketOptions.SslOnConnect. All other values will use SecureSocketOptions.StartTlsWhenAvailable.

Once a connection is established, properties such as AuthenticationMechanisms and Capabilities will be populated.

/// is null. /// -or- /// is null. /// /// is not between 0 and 65535. /// /// is not connected. /// -or- /// The is a zero-length string. /// /// The has been disposed. /// /// The is already connected. /// /// was set to /// /// and the IMAP server does not support the STARTTLS extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// An IMAP protocol error occurred. ///
public Connect ( Socket socket, string host, int port, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default(CancellationToken) ) : void
socket Socket The socket to use for the connection.
host string The host name to connect to.
port int The port to connect to. If the specified port is 0, then the default port will be used.
options SecureSocketOptions The secure socket options to when connecting.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

Connect() публичный Метод

Establish a connection to the specified IMAP server.

Establishes a connection to the specified IMAP or IMAP/S server.

If the port has a value of 0, then the options parameter is used to determine the default port to connect to. The default port used with SecureSocketOptions.SslOnConnect is 993. All other values will use a default port of 143.

If the options has a value of SecureSocketOptions.Auto, then the port is used to determine the default security options. If the port has a value of 993, then the default options used will be SecureSocketOptions.SslOnConnect. All other values will use SecureSocketOptions.StartTlsWhenAvailable.

Once a connection is established, properties such as AuthenticationMechanisms and Capabilities will be populated.

/// is null. /// /// is not between 0 and 65535. /// /// The is a zero-length string. /// /// The has been disposed. /// /// The is already connected. /// /// was set to /// /// and the IMAP server does not support the STARTTLS extension. /// /// The operation was canceled via the cancellation token. /// /// A socket error occurred trying to connect to the remote host. /// /// An I/O error occurred. /// /// An IMAP protocol error occurred. ///
public Connect ( string host, int port, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default(CancellationToken) ) : void
host string The host name to connect to.
port int The port to connect to. If the specified port is 0, then the default port will be used.
options SecureSocketOptions The secure socket options to when connecting.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

CreateImapFolder() защищенный Метод

Instantiate a new ImapFolder.

Creates a new ImapFolder instance.

This method's purpose is to allow subclassing ImapFolder.
/// is null. ///
protected CreateImapFolder ( MailKit.Net.Imap.ImapFolderConstructorArgs args ) : ImapFolder
args MailKit.Net.Imap.ImapFolderConstructorArgs The constructior arguments.
Результат ImapFolder

Disconnect() публичный Метод

Disconnect the service.
If quit is true, a LOGOUT command will be issued in order to disconnect cleanly.
/// The has been disposed. ///
public Disconnect ( bool quit, CancellationToken cancellationToken = default(CancellationToken) ) : void
quit bool If set to true, a LOGOUT command will be issued in order to disconnect cleanly.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

Dispose() защищенный Метод

Releases the unmanaged resources used by the ImapClient and optionally releases the managed resources.
Releases the unmanaged resources used by the ImapClient and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; /// false to release only the unmanaged resources.
Результат void

EnableQuickResync() публичный Метод

Enable the QRESYNC feature.

Enables the QRESYNC feature.

The QRESYNC extension improves resynchronization performance of folders by querying the IMAP server for a list of changes when the folder is opened using the ImapFolder.Open(FolderAccess,uint,ulong,System.Collections.Generic.IList<UniqueId>,System.Threading.CancellationToken) method.

If this feature is enabled, the MailFolder.MessageExpunged event is replaced with the MailFolder.MessagesVanished event.

This method needs to be called immediately after calling one of the Authenticate methods, before opening any folders.

/// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// Quick resynchronization needs to be enabled before selecting a folder. /// /// The IMAP server does not support the QRESYNC extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the ENABLE command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public EnableQuickResync ( CancellationToken cancellationToken = default(CancellationToken) ) : void
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

EnableUTF8() публичный Метод

Enable the UTF8=ACCEPT extension.
Enables the UTF8=ACCEPT extension.
/// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// UTF8=ACCEPT needs to be enabled before selecting a folder. /// /// The IMAP server does not support the UTF8=ACCEPT extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the ENABLE command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public EnableUTF8 ( CancellationToken cancellationToken = default(CancellationToken) ) : void
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

EnableUTF8Async() публичный Метод

Enable the UTF8=ACCEPT extension.
Enables the UTF8=ACCEPT extension.
/// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// UTF8=ACCEPT needs to be enabled before selecting a folder. /// /// The IMAP server does not support the UTF8=ACCEPT extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the ENABLE command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public EnableUTF8Async ( CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат System.Threading.Task

GetFolder() публичный Метод

Get the folder for the specified namespace.
Gets the folder for the specified namespace.
/// is null. /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The folder could not be found. ///
public GetFolder ( FolderNamespace @namespace ) : IMailFolder
@namespace FolderNamespace
Результат IMailFolder

GetFolder() публичный Метод

Get the specified special folder.
Not all IMAP servers support special folders. Only IMAP servers supporting the ImapCapabilities.SpecialUse or ImapCapabilities.XList extensions may have special folders.
/// is out of range. /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The IMAP server does not support the SPECIAL-USE nor XLIST extensions. ///
public GetFolder ( SpecialFolder folder ) : IMailFolder
folder SpecialFolder The type of special folder.
Результат IMailFolder

GetFolder() публичный Метод

Get the folder for the specified path.
Gets the folder for the specified path.
/// is null. /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The operation was canceled via the cancellation token. /// /// The folder could not be found. /// /// An I/O error occurred. /// /// The server replied to the IDLE command with a NO or BAD response. /// /// The server responded with an unexpected token. ///
public GetFolder ( string path, CancellationToken cancellationToken = default(CancellationToken) ) : IMailFolder
path string The folder path.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат IMailFolder

GetFolders() публичный Метод

Get all of the folders within the specified namespace.
Gets all of the folders within the specified namespace.
/// is null. /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The operation was canceled via the cancellation token. /// /// The namespace folder could not be found. /// /// An I/O error occurred. /// /// The server replied to the LIST or LSUB command with a NO or BAD response. /// /// The server responded with an unexpected token. ///
public GetFolders ( FolderNamespace @namespace, StatusItems items = StatusItems.None, bool subscribedOnly = false, CancellationToken cancellationToken = default(CancellationToken) ) : IList
@namespace FolderNamespace
items StatusItems The status items to pre-populate.
subscribedOnly bool If set to true, only subscribed folders will be listed.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат IList

GetMetadata() публичный Метод

Gets the specified metadata.
Gets the specified metadata.
/// is null. /// -or- /// is null. /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The IMAP server does not support the METADATA extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server's response contained unexpected tokens. /// /// The server replied with a NO or BAD response. ///
public GetMetadata ( MetadataOptions options, IEnumerable tags, CancellationToken cancellationToken = default(CancellationToken) ) : MetadataCollection
options MetadataOptions The metadata options.
tags IEnumerable The metadata tags.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат MetadataCollection

GetMetadata() публичный Метод

Gets the specified metadata.
Gets the specified metadata.
/// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The IMAP server does not support the METADATA extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server's response contained unexpected tokens. /// /// The server replied with a NO or BAD response. ///
public GetMetadata ( MetadataTag tag, CancellationToken cancellationToken = default(CancellationToken) ) : string
tag MetadataTag The metadata tag.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат string

Identify() публичный Метод

Identify the client implementation to the server and obtain the server implementation details.

Passes along the client implementation details to the server while also obtaining implementation details from the server.

If the clientImplementation is null or no properties have been set, no identifying information will be sent to the server.

Security Implications

This command has the danger of violating the privacy of users if misused. Clients should notify users that they send the ID command.

It is highly desirable that implementations provide a method of disabling ID support, perhaps by not calling this method at all, or by passing null as the clientImplementation argument.

Implementors must exercise extreme care in adding properties to the clientImplementation. Some properties, such as a processor ID number, Ethernet address, or other unique (or mostly unique) identifier would allow tracking of users in ways that violate user privacy expectations and may also make it easier for attackers to exploit security holes in the client.

/// The has been disposed. /// /// The is not connected. /// /// The IMAP server does not support the ID extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the ID command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public Identify ( MailKit.Net.Imap.ImapImplementation clientImplementation, CancellationToken cancellationToken = default(CancellationToken) ) : MailKit.Net.Imap.ImapImplementation
clientImplementation MailKit.Net.Imap.ImapImplementation The client implementation.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат MailKit.Net.Imap.ImapImplementation

IdentifyAsync() публичный Метод

Asynchronously identify the client implementation to the server and obtain the server implementation details.

Passes along the client implementation details to the server while also obtaining implementation details from the server.

If the clientImplementation is null or no properties have been set, no identifying information will be sent to the server.

Security Implications

This command has the danger of violating the privacy of users if misused. Clients should notify users that they send the ID command.

It is highly desirable that implementations provide a method of disabling ID support, perhaps by not calling this method at all, or by passing null as the clientImplementation argument.

Implementors must exercise extreme care in adding properties to the clientImplementation. Some properties, such as a processor ID number, Ethernet address, or other unique (or mostly unique) identifier would allow tracking of users in ways that violate user privacy expectations and may also make it easier for attackers to exploit security holes in the client.

/// The has been disposed. /// /// The is not connected. /// /// The IMAP server does not support the ID extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the ID command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public IdentifyAsync ( MailKit.Net.Imap.ImapImplementation clientImplementation, CancellationToken cancellationToken = default(CancellationToken) ) : Task
clientImplementation MailKit.Net.Imap.ImapImplementation The client implementation.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат Task

Idle() публичный Метод

Toggle the ImapClient into the IDLE state.

When a client enters the IDLE state, the IMAP server will send events to the client as they occur on the selected folder. These events may include notifications of new messages arriving, expunge notifications, flag changes, etc.

Due to the nature of the IDLE command, a folder must be selected before a client can enter into the IDLE state. This can be done by opening a folder using MailKit.MailFolder.Open(FolderAccess,System.Threading.CancellationToken) or any of the other variants.

While the IDLE command is running, no other commands may be issued until the doneToken is cancelled.

It is especially important to cancel the doneToken before cancelling the cancellationToken when using SSL or TLS due to the fact that System.Net.Security.SslStream cannot be polled.
/// must be cancellable (i.e. cannot be used). /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// A has not been opened. /// /// The IMAP server does not support the IDLE extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the IDLE command with a NO or BAD response. /// /// The server responded with an unexpected token. ///
public Idle ( CancellationToken doneToken, CancellationToken cancellationToken = default(CancellationToken) ) : void
doneToken System.Threading.CancellationToken The cancellation token used to return to the non-idle state.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

IdleAsync() публичный Метод

Asynchronously toggle the ImapClient into the IDLE state.

When a client enters the IDLE state, the IMAP server will send events to the client as they occur on the selected folder. These events may include notifications of new messages arriving, expunge notifications, flag changes, etc.

Due to the nature of the IDLE command, a folder must be selected before a client can enter into the IDLE state. This can be done by opening a folder using MailKit.MailFolder.Open(FolderAccess,System.Threading.CancellationToken) or any of the other variants.

While the IDLE command is running, no other commands may be issued until the doneToken is cancelled.

It is especially important to cancel the doneToken before cancelling the cancellationToken when using SSL or TLS due to the fact that System.Net.Security.SslStream cannot be polled.
/// must be cancellable (i.e. cannot be used). /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// A has not been opened. /// /// The IMAP server does not support the IDLE extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the IDLE command with a NO or BAD response. /// /// The server responded with an unexpected token. ///
public IdleAsync ( CancellationToken doneToken, CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task
doneToken System.Threading.CancellationToken The cancellation token used to return to the non-idle state.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат System.Threading.Task

ImapClient() публичный Метод

Initializes a new instance of the MailKit.Net.Imap.ImapClient class.
Before you can retrieve messages with the ImapClient, you must first call one of the Connect methods and then authenticate with the one of the Authenticate methods.
public ImapClient ( ) : System
Результат System

ImapClient() публичный Метод

Initializes a new instance of the MailKit.Net.Imap.ImapClient class.
Before you can retrieve messages with the ImapClient, you must first call one of the Connect methods and then authenticate with the one of the Authenticate methods.
/// is null. ///
public ImapClient ( IProtocolLogger protocolLogger ) : System
protocolLogger IProtocolLogger The protocol logger.
Результат System

NoOp() публичный Метод

Ping the IMAP server to keep the connection alive.

The NOOP command is typically used to keep the connection with the IMAP server alive. When a client goes too long (typically 30 minutes) without sending any commands to the IMAP server, the IMAP server will close the connection with the client, forcing the client to reconnect before it can send any more commands.

The NOOP command also provides a great way for a client to check for new messages.

When the IMAP server receives a NOOP command, it will reply to the client with a list of pending updates such as EXISTS and RECENT counts on the currently selected folder. To receive these notifications, subscribe to the MailFolder.CountChanged and MailFolder.RecentChanged events, respectively.

For more information about the NOOP command, see rfc3501.

/// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the NOOP command with a NO or BAD response. /// /// The server responded with an unexpected token. ///
public NoOp ( CancellationToken cancellationToken = default(CancellationToken) ) : void
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

Reconnect() публичный Метод

Reconnect to the most recently connected IMAP server.

Reconnects to the most recently connected IMAP server. Once a successful connection is made, the session will then be re-authenticated using the account name used in the previous session and the password.

/// is null. /// /// The has been disposed. /// /// The is not connected. /// /// There is no previous session to restore. /// /// The operation was canceled via the cancellation token. /// /// Authentication using the supplied credentials has failed. /// /// A SASL authentication error occurred. /// /// The previous session was using the STARTTLS extension but the /// IMAP server no longer supports it. /// /// An I/O error occurred. /// /// An IMAP protocol error occurred. ///
public Reconnect ( string password, CancellationToken cancellationToken = default(CancellationToken) ) : void
password string The password.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void

ReconnectAsync() публичный Метод

Asynchronously reconnect to the most recently connected IMAP server.

Asynchronously reconnects to the most recently connected IMAP server. Once a successful connection is made, the session will then be re-authenticated using the account name used in the previous session and the password.

/// is null. /// /// The has been disposed. /// /// The is not connected. /// /// There is no previous session to restore. /// /// The operation was canceled via the cancellation token. /// /// Authentication using the supplied credentials has failed. /// /// A SASL authentication error occurred. /// /// The previous session was using the STARTTLS extension but the /// IMAP server no longer supports it. /// /// An I/O error occurred. /// /// An IMAP protocol error occurred. ///
public ReconnectAsync ( string password, CancellationToken cancellationToken = default(CancellationToken) ) : System.Threading.Task
password string The password.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат System.Threading.Task

SetMetadata() публичный Метод

Sets the specified metadata.
Sets the specified metadata.
/// is null. /// /// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The IMAP server does not support the METADATA extension. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server's response contained unexpected tokens. /// /// The server replied with a NO or BAD response. ///
public SetMetadata ( MetadataCollection metadata, CancellationToken cancellationToken = default(CancellationToken) ) : void
metadata MetadataCollection The metadata.
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void