Class ImapClient
Receives and manages mail via IMAP4rev1/IMAP4rev2 (RFC 9051). One instance maintains a single connection. Not thread-safe; use one instance per thread. IDLE runs on a background thread and must not be combined with other commands on the same instance.
Implements
Inherited Members
Namespace: DRIT.Mail.Rfc.Imap
Assembly: DRIT.Mail.dll
Syntax
public sealed class ImapClient : IDisposable
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Constructors
View SourceImapClient(ImapClientOptions)
Initializes a new instance of the ImapClient class with a real TCP transport.
Declaration
public ImapClient(ImapClientOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapClientOptions | options | The client configuration. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
ImapClient(ImapClientOptions, ITextProtocolTransport)
Initializes a new instance of the ImapClient class with a custom transport. Used for testing with an in-process transport.
Declaration
public ImapClient(ImapClientOptions options, ITextProtocolTransport transport)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapClientOptions | options | The client configuration. |
| ITextProtocolTransport | transport | The transport to use. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Properties
View SourceCapabilities
Gets the server capabilities advertised in the CAPABILITY response. Returns Empty before Connect() is called.
Declaration
public ImapServerCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ImapServerCapabilities |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
IsAuthenticated
Gets a value indicating whether the client has authenticated.
Declaration
public bool IsAuthenticated { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
IsConnected
Gets a value indicating whether the client is connected to the server.
Declaration
public bool IsConnected { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
IsEncrypted
Gets a value indicating whether the connection is encrypted (TLS).
Declaration
public bool IsEncrypted { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
IsIdleActive
Gets a value indicating whether an IDLE session is currently
active. While true, all commands except
Disconnect() and Dispose() throw
ImapIdleActiveException.
Declaration
public bool IsIdleActive { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
SelectedMailbox
Gets the currently selected mailbox, or null if no mailbox is selected.
Declaration
public ImapMailbox? SelectedMailbox { get; }
Property Value
| Type | Description |
|---|---|
| ImapMailbox |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Methods
View SourceAddFlags(ImapMessageSet, ImapMessageFlags)
Adds the specified flags to messages (STORE +FLAGS).
Declaration
public void AddFlags(ImapMessageSet messages, ImapMessageFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| ImapMessageFlags | flags | The flags to add. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
AddFlags(ImapMessageSet, params string[])
Adds user-defined keywords to messages (STORE +FLAGS).
Declaration
public void AddFlags(ImapMessageSet messages, params string[] keywords)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| string[] | keywords | The user-defined keywords (e.g. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Authenticate()
Authenticates with the server using the credentials configured in ImapClientOptions.
Declaration
public void Authenticate()
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Authenticate(SaslCredentials)
Authenticates with the specified credentials.
Declaration
public void Authenticate(SaslCredentials credentials)
Parameters
| Type | Name | Description |
|---|---|---|
| SaslCredentials | credentials | The username/password credentials. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Authenticate(SaslOAuth2Token)
Authenticates with the specified OAuth 2.0 token.
Declaration
public void Authenticate(SaslOAuth2Token token)
Parameters
| Type | Name | Description |
|---|---|---|
| SaslOAuth2Token | token | The OAuth 2.0 access token. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
CloseFolder()
Closes the currently selected mailbox (CLOSE, RFC 9051 §6.4.2).
Implicitly expunges messages marked as \Deleted.
Declaration
public void CloseFolder()
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Connect()
Connects to the IMAP server, reads the greeting, performs STARTTLS or implicit TLS upgrade as configured, and optionally authenticates.
Declaration
public void Connect()
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
CopyMessages(ImapMessageSet, string)
Copies messages to another mailbox (COPY, RFC 9051 §6.4.7).
Declaration
public void CopyMessages(ImapMessageSet messages, string destinationMailbox)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| string | destinationMailbox | The destination mailbox name. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
CreateFolder(string)
Creates a new mailbox (CREATE, RFC 9051 §6.3.3).
Declaration
public void CreateFolder(string mailboxName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mailboxName | The mailbox name to create. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
DeleteFolder(string)
Deletes a mailbox (DELETE, RFC 9051 §6.3.4).
Declaration
public void DeleteFolder(string mailboxName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mailboxName | The mailbox name to delete. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Disconnect()
Sends LOGOUT and closes the connection. Safe to call multiple times.
Declaration
public void Disconnect()
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Dispose()
Disposes the client, sending LOGOUT if still connected.
Declaration
public void Dispose()
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
ExamineFolder(string)
Selects a mailbox for read-only access (EXAMINE, RFC 9051 §6.3.2).
Declaration
public ImapMailbox ExamineFolder(string mailboxName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mailboxName | The mailbox name. |
Returns
| Type | Description |
|---|---|
| ImapMailbox | The mailbox metadata. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Expunge()
Permanently removes all messages marked \Deleted in the
currently selected mailbox (EXPUNGE, RFC 9051 §6.4.3).
Returns the sequence numbers of expunged messages (from
* N EXPUNGE untagged responses), which should be used
to renumber any local message sequence tracking.
Declaration
public IReadOnlyList<long> Expunge()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<long> | The list of expunged sequence numbers, in the order received. Sequence numbers greater than an expunged number must be decremented. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
FetchBodyPart(ImapMessageSet, string, long, int)
Fetches a partial body section (RFC 9051 §6.4.5). Used for
large-attachment streaming: BODY.PEEK[section]<offset.length>
fetches a byte range within the specified MIME section.
Declaration
public byte[] FetchBodyPart(ImapMessageSet messages, string section, long offset, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set (typically a single message). |
| string | section | The MIME section path (e.g. |
| long | offset | The byte offset within the section. |
| int | length | The number of bytes to fetch. |
Returns
| Type | Description |
|---|---|
| byte[] | The raw bytes of the partial body section. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
FetchMessage(ImapMessageSet, ImapFetchOptions)
Fetches a single message and parses it via Load(string).
Declaration
public MimeMessage FetchMessage(ImapMessageSet messages, ImapFetchOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set (typically a single message). |
| ImapFetchOptions | options | The fetch options (must include Body). |
Returns
| Type | Description |
|---|---|
| MimeMessage | The parsed MIME message. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
FetchMessageInfos(ImapMessageSet, ImapFetchOptions)
Fetches message information for the specified message set.
Declaration
public IReadOnlyList<ImapMessageInfo> FetchMessageInfos(ImapMessageSet messages, ImapFetchOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| ImapFetchOptions | options | The fetch options. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ImapMessageInfo> | The fetched message information. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
FetchMessageRaw(ImapMessageSet, ImapFetchOptions)
Fetches a single message as raw bytes.
Declaration
public byte[] FetchMessageRaw(ImapMessageSet messages, ImapFetchOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| ImapFetchOptions | options | The fetch options (must include Body). |
Returns
| Type | Description |
|---|---|
| byte[] | The raw message bytes. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
FetchMessages(ImapMessageSet, ImapFetchOptions)
Fetches multiple messages and parses them via Load(string).
Declaration
public IReadOnlyList<MimeMessage> FetchMessages(ImapMessageSet messages, ImapFetchOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| ImapFetchOptions | options | The fetch options. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<MimeMessage> | The parsed MIME messages. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
GetCapabilities()
Queries the server for its capabilities (CAPABILITY, RFC 9051 §6.1.1).
Declaration
public ImapServerCapabilities GetCapabilities()
Returns
| Type | Description |
|---|---|
| ImapServerCapabilities | The server capabilities. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
GetFolderStatus(string, ImapStatusItems)
Queries mailbox status without selecting it (STATUS, RFC 9051 §6.3.10).
Declaration
public ImapMailboxStatus GetFolderStatus(string mailboxName, ImapStatusItems items)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mailboxName | The mailbox name to query. |
| ImapStatusItems | items | The status items to request. |
Returns
| Type | Description |
|---|---|
| ImapMailboxStatus | The mailbox status. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
ListFolders(string, string)
Lists mailboxes matching the given pattern (LIST, RFC 9051
§6.3.8). The reference is the base context (often empty) and
the pattern uses IMAP wildcards (* = any depth,
% = one level).
Declaration
public IReadOnlyList<ImapFolder> ListFolders(string reference = "", string pattern = "*")
Parameters
| Type | Name | Description |
|---|---|---|
| string | reference | The reference mailbox name (often empty). |
| string | pattern | The mailbox name pattern. Default is |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ImapFolder> | The list of folders matching the pattern. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
ListSubscribedFolders(string, string)
Lists subscribed mailboxes matching the given pattern (LSUB, RFC 9051 §6.3.9).
Declaration
public IReadOnlyList<ImapFolder> ListSubscribedFolders(string reference = "", string pattern = "*")
Parameters
| Type | Name | Description |
|---|---|---|
| string | reference | The reference mailbox name (often empty). |
| string | pattern | The mailbox name pattern. Default is |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ImapFolder> | The list of subscribed folders matching the pattern. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
MoveMessages(ImapMessageSet, string)
Moves messages to another mailbox (MOVE, RFC 6851). Requires
the server to advertise the MOVE capability.
Declaration
public void MoveMessages(ImapMessageSet messages, string destinationMailbox)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| string | destinationMailbox | The destination mailbox name. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Noop()
Sends a NOOP command to keep the connection alive (RFC 9051 §6.1.2).
Declaration
public void Noop()
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
RemoveFlags(ImapMessageSet, ImapMessageFlags)
Removes the specified flags from messages (STORE -FLAGS).
Declaration
public void RemoveFlags(ImapMessageSet messages, ImapMessageFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| ImapMessageFlags | flags | The flags to remove. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
RemoveFlags(ImapMessageSet, params string[])
Removes user-defined keywords from messages (STORE -FLAGS).
Declaration
public void RemoveFlags(ImapMessageSet messages, params string[] keywords)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| string[] | keywords | The user-defined keywords to remove. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
RenameFolder(string, string)
Renames a mailbox (RENAME, RFC 9051 §6.3.5).
Declaration
public void RenameFolder(string oldName, string newName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | oldName | The current mailbox name. |
| string | newName | The new mailbox name. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Search(ImapSearchCriteria)
Searches the selected mailbox for messages matching the specified criteria (SEARCH, RFC 9051 §6.4.4). Returns the matching sequence numbers.
Declaration
public IReadOnlyList<long> Search(ImapSearchCriteria criteria)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapSearchCriteria | criteria | The search criteria. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<long> | The matching sequence numbers. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
SearchAndFetch(ImapSearchCriteria, ImapFetchOptions)
Searches for messages matching the specified criteria, then fetches the matching messages. This is a convenience wrapper over Search(ImapSearchCriteria) + FetchMessages(ImapMessageSet, ImapFetchOptions).
Declaration
public IReadOnlyList<MimeMessage> SearchAndFetch(ImapSearchCriteria criteria, ImapFetchOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapSearchCriteria | criteria | The search criteria. |
| ImapFetchOptions | options | The fetch options (must include Body). |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<MimeMessage> | The parsed MIME messages matching the search. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
SearchUids(ImapSearchCriteria)
Searches the selected mailbox for messages matching the specified criteria, returning UIDs (UID SEARCH, RFC 9051 §6.4.4).
Declaration
public IReadOnlyList<long> SearchUids(ImapSearchCriteria criteria)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapSearchCriteria | criteria | The search criteria. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<long> | The matching UIDs. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
SelectFolder(string)
Selects a mailbox for read-write access (SELECT, RFC 9051 §6.3.1).
Declaration
public ImapMailbox SelectFolder(string mailboxName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mailboxName | The mailbox name (e.g. |
Returns
| Type | Description |
|---|---|
| ImapMailbox | The mailbox metadata. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
SetFlags(ImapMessageSet, ImapMessageFlags, ImapFlagOperation)
Sets, adds, or removes message flags (STORE, RFC 9051 §6.4.6).
Declaration
public void SetFlags(ImapMessageSet messages, ImapMessageFlags flags, ImapFlagOperation op)
Parameters
| Type | Name | Description |
|---|---|---|
| ImapMessageSet | messages | The message set. |
| ImapMessageFlags | flags | The system flags to store. |
| ImapFlagOperation | op | The flag operation. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
StartIdle()
Starts an IDLE session (RFC 2177) that pushes server notifications
via events. Requires the server to advertise the IDLE
capability. A mailbox must be selected. The returned
ImapIdleSession runs a background thread that reads
untagged responses and raises events. Callers must call
Stop() before issuing any other
command on this client.
Declaration
public ImapIdleSession StartIdle()
Returns
| Type | Description |
|---|---|
| ImapIdleSession | The IDLE session. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
Exceptions
| Type | Condition |
|---|---|
| ImapProtocolException | Thrown if the server does not advertise IDLE. |
| ImapIdleActiveException | Thrown if an IDLE session is already active. |
SubscribeFolder(string)
Subscribes to a mailbox (SUBSCRIBE, RFC 9051 §6.3.6).
Declaration
public void SubscribeFolder(string mailboxName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mailboxName | The mailbox name to subscribe to. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.
UnsubscribeFolder(string)
Unsubscribes from a mailbox (UNSUBSCRIBE, RFC 9051 §6.3.7).
Declaration
public void UnsubscribeFolder(string mailboxName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mailboxName | The mailbox name to unsubscribe from. |
Remarks
Connection lifecycle. A ImapClient wraps a
single TCP connection. Call Connect() to open it,
Authenticate() to log in, and Disconnect()
(or Dispose()) to close it. If
AutoConnect is true
(the default), operations connect automatically.
Timeouts. All read and write operations honor Timeout. A timeout throws ImapTimeoutException and leaves the client disconnected.
Connection drops. If the server closes the connection
unexpectedly (e.g. after a BYE response, a network
interruption, or an idle timeout), the next read or write will
throw ImapProtocolException or
ImapTimeoutException and the client will be left
in the disconnected state. To recover, dispose the client and
create a new one with Connect() +
Authenticate() + SelectFolder(string). Any
cached sequence numbers are invalid after a reconnect; use UIDs
(FromUids(IEnumerable<long>)) for stable message
identification across reconnects, provided the mailbox
UIDVALIDITY value has not changed.