ImapClient Class
Represents mail client that can be used for manipulating folders and retrieving messages using Internet Mail Access Protocol (IMAP).
public sealed class ImapClient : IDisposable
Public NotInheritable Class ImapClient
Implements IDisposable
- Inheritance:
- System.ObjectImapClient
Implements
Remarks
ImapClient is implemented according to RFC 3501.
Constructors
ImapClient(String)
Initializes new instance of ImapClient class with specified host address.
Parameters
host
- System.String
The address of the server.
ImapClient(String, ConnectionSecurity, Boolean)
Initializes new instance of ImapClient class with specified host address, ConnectionSecurity option and option to ignore SSL certificate errors.
public ImapClient(string host, ConnectionSecurity security, bool acceptAnyCertificate)
Public Sub New(host As String, security As ConnectionSecurity, acceptAnyCertificate As Boolean)
Parameters
host
- System.String
The address of the server.
security
- ConnectionSecurity
A constant that determines connection security level.
acceptAnyCertificate
- System.Boolean
True
to ignore any SSL certificate errors; otherwise, false
.
ImapClient(String, Boolean)
Initializes new instance of ImapClient class with specified host address and option to ignore SSL certificate errors.
public ImapClient(string host, bool acceptAnyCertificate)
Public Sub New(host As String, acceptAnyCertificate As Boolean)
Parameters
host
- System.String
The address of the server.
acceptAnyCertificate
- System.Boolean
True
to ignore any SSL certificate errors; otherwise, false
.
ImapClient(String, Int32)
Initializes new instance of ImapClient class with specified host address and port number.
Parameters
host
- System.String
The address of the server.
port
- System.Int32
An integer value between 1 and 65535 indicating remote server IP port. Value 0 indicates that client will use default port value for specified connection security level.
ImapClient(String, Int32, ConnectionSecurity)
Initializes new instance of ImapClient class with specified host address, port number and ConnectionSecurity option.
public ImapClient(string host, int port, ConnectionSecurity security)
Public Sub New(host As String, port As Integer, security As ConnectionSecurity)
Parameters
host
- System.String
The address of the server.
port
- System.Int32
An integer value between 1 and 65535 indicating remote server IP port. Value 0 indicates that client will use default port value for specified connection security level.
security
- ConnectionSecurity
A constant that determines connection security level.
ImapClient(String, Int32, ConnectionSecurity, RemoteCertificateValidationCallback)
Initializes new instance of ImapClient class with specified host address, port number, ConnectionSecurity option and host certificate validation delegate method.
public ImapClient(string host, int port, ConnectionSecurity security, RemoteCertificateValidationCallback certificateValidationCallback)
Public Sub New(host As String, port As Integer, security As ConnectionSecurity, certificateValidationCallback As RemoteCertificateValidationCallback)
Parameters
host
- System.String
The address of the server.
port
- System.Int32
An integer value between 1 and 65535 indicating remote server IP port. Value 0 indicates that client will use default port value for specified connection security level.
security
- ConnectionSecurity
A constant that determines connection security level.
certificateValidationCallback
- System.Net.Security.RemoteCertificateValidationCallback
A delegate method for validating server SSL certificate on successful connection.
Properties
ConnectTimeout
Gets or sets the connect timeout.
Property Value
- System.TimeSpan
The connect timeout.
Exceptions
- System.InvalidOperationException
Timeout cannot be set while client is connected.
Host
Gets the server address.
Property Value
- System.String
The server address.
IdleEnabled
Gets whether or not IDLE mode is enabled.
Property Value
- System.Boolean
True
if IDLE mode is enabled; otherwise, false
.
IsAuthenticated
Gets whether or not client is authenticated.
Property Value
- System.Boolean
True
if client is authenticated; otherwise, false
.
Remarks
Property indicates whether or not client is currently authenticated with server using Authenticate(String, String) or Authenticate(String, String, ImapAuthentication) method.
IsConnected
Gets whether or not client is connected to remote server.
Property Value
- System.Boolean
True
if client is connected; otherwise, false
.
LocalEndPoint
Gets or sets the local IP address and port.
Property Value
- System.Net.IPEndPoint
The local IP address and port.
Remarks
Use this property to force the client to use a specific local IP address and port for server connection. If not specified or null, the system will automatically select the values. Value must be set before calling the Connect() method.
Exceptions
- System.InvalidOperationException
Local IP address and port cannot be set while client is connected.
LogOutput
Gets or sets the log output writer.
Property Value
- System.IO.TextWriter
The log output writer.
Remarks
Setting this property to a non-null value, enables communication logging. All commands and responses between the client and server will be written to the provided System.IO.TextWriter. Logging is disabled by setting this property to null.
Port
Gets the server IP port.
Property Value
- System.Int32
The server IP port.
ReadTimeout
Gets or sets the read timeout.
Property Value
- System.TimeSpan
The read timeout.
Exceptions
- System.InvalidOperationException
Timeout cannot be set while client is connected.
Security
Gets the current connection security mode.
public ConnectionSecurity Security { get; }
Public ReadOnly Property Security As ConnectionSecurity
Property Value
The current connection security mode.
SelectedFolder
Gets the currently selected IMAP folder.
public ImapFolderStatus SelectedFolder { get; }
Public ReadOnly Property SelectedFolder As ImapFolderStatus
Property Value
The currently selected IMAP folder or null if no folder is selected.
Remarks
This property is set by calling SelectInbox() or SelectFolder(String, Boolean) method.
SupportedAuthentications
Gets collection of supported authentication mechanisms.
public ReadOnlyCollection<ImapAuthentication> SupportedAuthentications { get; }
Public ReadOnly Property SupportedAuthentications As ReadOnlyCollection(Of ImapAuthentication)
Property Value
- System.Collections.ObjectModel.ReadOnlyCollection<ImapAuthentication>
A read-only collection of supported authentication mechanisms.
Remarks
Collection is populated on successful connect. Values are sorted from strongest to weakest mechanism.
SupportedCapabilities
Gets the collection of supported capabilities.
public ReadOnlyCollection<ImapCapability> SupportedCapabilities { get; }
Public ReadOnly Property SupportedCapabilities As ReadOnlyCollection(Of ImapCapability)
Property Value
- System.Collections.ObjectModel.ReadOnlyCollection<ImapCapability>
A read-only collection of supported capabilities.
Remarks
Collection is populated on successful connect, and refreshed after successful authentication.
WriteTimeout
Gets or sets the write timeout.
Property Value
- System.TimeSpan
The write timeout.
Exceptions
- System.InvalidOperationException
Timeout cannot be set while client is connected.
Methods
AddMessageFlags(Int32, IEnumerable<String>)
Adds the specified flags without modifying existing message flags.
public void AddMessageFlags(int messageNumber, IEnumerable<string> flags)
Public Sub AddMessageFlags(messageNumber As Integer, flags As IEnumerable(Of String))
Parameters
messageNumber
- System.Int32
The message number.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to add.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
- System.ArgumentNullException
Flags parameter is null.
AddMessageFlags(Int32, String[])
Adds the specified flags without modifying existing message flags.
public void AddMessageFlags(int messageNumber, params string[] flags)
Public Sub AddMessageFlags(messageNumber As Integer, ParamArray flags As String())
Parameters
messageNumber
- System.Int32
The message number.
flags
- System.String[]
A collection of flags to add.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
- System.ArgumentNullException
Flags parameter is null.
AddMessageFlags(String, IEnumerable<String>)
Adds the specified flags without modifying existing message flags.
public void AddMessageFlags(string uid, IEnumerable<string> flags)
Public Sub AddMessageFlags(uid As String, flags As IEnumerable(Of String))
Parameters
uid
- System.String
The message id.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to add.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
- System.ArgumentNullException
Flags parameter is null.
AddMessageFlags(String, String[])
Adds the specified flags without modifying existing message flags.
public void AddMessageFlags(string uid, params string[] flags)
Public Sub AddMessageFlags(uid As String, ParamArray flags As String())
Parameters
uid
- System.String
The message id.
flags
- System.String[]
A collection of flags to add.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
- System.ArgumentNullException
Flags parameter is null.
AddMessageRangeFlags(Int32, Int32, IEnumerable<String>)
Adds the specified flags to a range of messages without modifying existing message flags.
public void AddMessageRangeFlags(int startingNumber, int endingNumber, IEnumerable<string> flags)
Public Sub AddMessageRangeFlags(startingNumber As Integer, endingNumber As Integer, flags As IEnumerable(Of String))
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to add.
Exceptions
- System.InvalidOperationException
No folder is selected.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
- System.ArgumentNullException
Flags parameter is null.
AddMessageRangeFlags(Int32, Int32, String[])
Adds the specified flags to a range of messages without modifying existing message flags.
public void AddMessageRangeFlags(int startingNumber, int endingNumber, params string[] flags)
Public Sub AddMessageRangeFlags(startingNumber As Integer, endingNumber As Integer, ParamArray flags As String())
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
flags
- System.String[]
A collection of flags to add.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
- System.ArgumentNullException
Flags parameter is null.
Authenticate(String, String)
Authenticates client with specified user name and password.
public void Authenticate(string userName, string password)
Public Sub Authenticate(userName As String, password As String)
Parameters
userName
- System.String
The user name.
password
- System.String
The password for the user name.
Remarks
When calling the Authenticate(String, String) method, the strongest possible password-based authentication mechanism will be used from the SupportedAuthentications collection.
Method authenticates connected client with remote host. Connected client cannot be reauthenticated. You have to call Disconnect() first.
Exceptions
- System.InvalidOperationException
Client is not connected or Client is already authenticated.
- System.ArgumentException
Specified user name is null or empty or Specified password is null or empty.
- System.NotSupportedException
Remote host doesn't support authentication.
Authenticate(String, String, ImapAuthentication)
Authenticates client with specified user name, password or access token, and ImapAuthentication mechanism.
public void Authenticate(string userName, string passwordOrToken, ImapAuthentication authentication)
Public Sub Authenticate(userName As String, passwordOrToken As String, authentication As ImapAuthentication)
Parameters
userName
- System.String
The user name.
passwordOrToken
- System.String
The password or access token for the user name.
authentication
- ImapAuthentication
A constant that specifies which authentication mechanism to use.
Remarks
Method authenticates connected client with remote host. Connected client cannot be re-authenticated. You have to call Disconnect() first.
Exceptions
- System.InvalidOperationException
Client is not connected or Client is already authenticated.
- System.ArgumentException
Specified authentication mechanism is not supported or Specified user name is null or empty or Specified password or access token is null or empty.
CloseSelectedFolder()
Closes the currently selected folder.
Remarks
Closing currently selected folder will set SelectedFolder property to null.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
Connect()
Connects to the server.
Exceptions
- System.InvalidOperationException
Using StartTls for the server which doesn't support it or Client is already connected.
- System.TimeoutException
The server failed to respond in given time.
Connect(SslProtocols)
Connects to the server using specified SSL protocols.
public void Connect(SslProtocols sslProtocols)
Public Sub Connect(sslProtocols As SslProtocols)
Parameters
sslProtocols
- System.Security.Authentication.SslProtocols
Remarks
The client connects to the server using the most secure protocol out of the specified protocols. This method is provided for .NET Framework 4.5 and older since they don’t support TLS 1.2 and greater by default. To specify them, use the following numeric values: 3072 for TLS 1.2, and 12288 for TLS 1.3.
Exceptions
- System.InvalidOperationException
Using StartTls for the server which doesn't support it or Client is already connected.
- System.TimeoutException
The server failed to respond in given time.
CreateFolder(String)
Creates new folder with specified name.
Parameters
name
- System.String
The full folder name.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
- System.ArgumentException
Folder name is null or empty.
DeleteFolder(String)
Deletes the specified folder.
Parameters
name
- System.String
The full folder name.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
- System.ArgumentException
Folder name is null or empty.
DeleteMessage(Int32, Boolean)
Deletes the specified message.
public void DeleteMessage(int messageNumber, bool expunge)
Public Sub DeleteMessage(messageNumber As Integer, expunge As Boolean)
Parameters
messageNumber
- System.Int32
The message number.
expunge
- System.Boolean
True
to delete message immediately from the server; otherwise, false
.
Remarks
Setting expunge to true will delete specified message from the server and that message cannot be undeleted. By setting expunge to false, specified message will just be marked for deletion, but it won't be removed from the server until Expunge() is called.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
DeleteMessage(String, Boolean)
Deletes the specified message.
public void DeleteMessage(string uid, bool expunge)
Public Sub DeleteMessage(uid As String, expunge As Boolean)
Parameters
uid
- System.String
The message id.
expunge
- System.Boolean
True
to delete message immediately from the server; otherwise, false
.
Remarks
Setting expunge to true will specified delete message from the server and that message cannot be undeleted. By setting expunge to false, specified message will just be marked for deletion, but it won't be removed from the server until Expunge() is called.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
DeleteMessageRange(Int32, Int32, Boolean)
Deletes the specified messages.
public void DeleteMessageRange(int startingNumber, int endingNumber, bool expunge)
Public Sub DeleteMessageRange(startingNumber As Integer, endingNumber As Integer, expunge As Boolean)
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
expunge
- System.Boolean
True
to delete message immediately from the server; otherwise, false
.
Remarks
Setting expunge to true will delete specified messages from the server and those messages cannot be undeleted. By setting expunge to false, specified messages will just be marked for deletion, but they won't be removed from the server until Expunge() is called.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
Disconnect()
Disconnects client from the server.
Dispose()
Disconnects client from the server and disposes all used resources.
Expunge()
Expunges the selected folder.
Remarks
All messages with \Deleted flag set are removed from selected folder.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
GetFolderStatus(String)
Gets the status of specified folder.
public ImapFolderStatus GetFolderStatus(string name)
Public Function GetFolderStatus(name As String) As ImapFolderStatus
Parameters
name
- System.String
The full folder name.
Returns
The status of specified folder.
Remarks
This method doesn't change SelectedFolder property value.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
- System.ArgumentException
Folder name is null or empty.
- System.FormatException
Server returned invalid response.
GetHeaders(Int32)
Gets the headers for the specified message.
public HeaderCollection GetHeaders(int messageNumber)
Public Function GetHeaders(messageNumber As Integer) As HeaderCollection
Parameters
messageNumber
- System.Int32
The message number.
Returns
A collection of message headers.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
GetHeaders(String)
Gets the headers for the specified message.
public HeaderCollection GetHeaders(string uid)
Public Function GetHeaders(uid As String) As HeaderCollection
Parameters
uid
- System.String
The message id.
Returns
A collection of message headers.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported.
- System.ArgumentException
Message id is null or empty.
GetMessage(Int32)
Gets the specified message.
public MailMessage GetMessage(int messageNumber)
Public Function GetMessage(messageNumber As Integer) As MailMessage
Parameters
messageNumber
- System.Int32
The message number.
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
Free license limitation exceeded.
GetMessage(Int32, Boolean)
Gets the specified message.
public MailMessage GetMessage(int messageNumber, bool withAttachments)
Public Function GetMessage(messageNumber As Integer, withAttachments As Boolean) As MailMessage
Parameters
messageNumber
- System.Int32
The message number.
withAttachments
- System.Boolean
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
Free license limitation exceeded.
GetMessage(String)
Gets the specified message.
public MailMessage GetMessage(string uid)
Public Function GetMessage(uid As String) As MailMessage
Parameters
uid
- System.String
The message id.
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
Free license limitation exceeded.
GetMessage(String, Boolean)
Gets the specified message.
public MailMessage GetMessage(string uid, bool withAttachments)
Public Function GetMessage(uid As String, withAttachments As Boolean) As MailMessage
Parameters
uid
- System.String
The message id.
withAttachments
- System.Boolean
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
Free license limitation exceeded.
GetMessageFlags(Int32)
Gets the message flags.
public ReadOnlyCollection<string> GetMessageFlags(int messageNumber)
Public Function GetMessageFlags(messageNumber As Integer) As ReadOnlyCollection(Of String)
Parameters
messageNumber
- System.Int32
The message number.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<System.String>
A read-only collection of message flags.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
GetMessageFlags(String)
Gets the message flags.
public ReadOnlyCollection<string> GetMessageFlags(string uid)
Public Function GetMessageFlags(uid As String) As ReadOnlyCollection(Of String)
Parameters
uid
- System.String
The message id.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<System.String>
A read-only collection of message flags.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Invalid message id or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
GetMessageRange(Int32, Int32)
Gets the collection of specified messages.
public ReadOnlyCollection<MailMessage> GetMessageRange(int startingNumber, int endingNumber)
Public Function GetMessageRange(startingNumber As Integer, endingNumber As Integer) As ReadOnlyCollection(Of MailMessage)
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<MailMessage>
A read-only collection of specified messages.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
Free license limitation exceeded.
IdleDisable()
Disables IDLE mode.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
IdleEnable()
Enables IDLE mode with the refresh interval set to 29 minutes.
IdleEnable(Int32)
Enables IDLE mode with the specified refresh interval.
public void IdleEnable(int refreshInterval)
Public Sub IdleEnable(refreshInterval As Integer)
Parameters
refreshInterval
- System.Int32
The refresh interval in minutes.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.NotSupportedException
Server doesn't support IDLE command.
KeepAlive()
Executes NOOP command.
Remarks
Executing NOOP command prevents server from terminating connection due to client inactivity.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
ListFolders()
Lists all folders on the server.
public ReadOnlyCollection<ImapFolderInfo> ListFolders()
Public Function ListFolders As ReadOnlyCollection(Of ImapFolderInfo)
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<ImapFolderInfo>
A read-only collection of all folders on the server.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
ListMessages()
Lists all messages in the selected folder.
public ReadOnlyCollection<ImapMessageInfo> ListMessages()
Public Function ListMessages As ReadOnlyCollection(Of ImapMessageInfo)
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<ImapMessageInfo>
A read-only collection of all messages in the selected folder. If folder is empty, returns an empty collection.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
ListMessages(Int32, Int32)
Lists specified range of messages in the selected folder.
public ReadOnlyCollection<ImapMessageInfo> ListMessages(int startingNumber, int endingNumber)
Public Function ListMessages(startingNumber As Integer, endingNumber As Integer) As ReadOnlyCollection(Of ImapMessageInfo)
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<ImapMessageInfo>
A read-only collection of specified messages in the selected folder.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
ListSubscribedFolders()
Lists all subscribed folders on the server.
public ReadOnlyCollection<ImapFolderInfo> ListSubscribedFolders()
Public Function ListSubscribedFolders As ReadOnlyCollection(Of ImapFolderInfo)
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<ImapFolderInfo>
A read-only collection of all subscribed folders on the server.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
MoveMessage(Int32, String)
Moves the specified message to another folder.
public void MoveMessage(int messageNumber, string destinationFolder)
Public Sub MoveMessage(messageNumber As Integer, destinationFolder As String)
Parameters
messageNumber
- System.Int32
The message number.
destinationFolder
- System.String
The destination folder name.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentException
Destination folder is null or empty.
MoveMessage(String, String)
Moves the specified message to another folder.
public void MoveMessage(string uid, string destinationFolder)
Public Sub MoveMessage(uid As String, destinationFolder As String)
Parameters
uid
- System.String
The message id.
destinationFolder
- System.String
The destination folder name.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentException
Destination folder is null or empty.
MoveMessageRange(Int32, Int32, String)
Moves the specified range of messages to another folder.
public void MoveMessageRange(int startingNumber, int endingNumber, string destinationFolder)
Public Sub MoveMessageRange(startingNumber As Integer, endingNumber As Integer, destinationFolder As String)
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
destinationFolder
- System.String
The destination folder name.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
- System.ArgumentException
Destination folder is null or empty.
PeekMessage(Int32)
Gets the specified message without setting the Seen flag.
public MailMessage PeekMessage(int messageNumber)
Public Function PeekMessage(messageNumber As Integer) As MailMessage
Parameters
messageNumber
- System.Int32
The message number.
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
Free license limitation exceeded.
PeekMessage(Int32, Boolean)
Gets the specified message without setting the Seen flag.
public MailMessage PeekMessage(int messageNumber, bool withAttachments)
Public Function PeekMessage(messageNumber As Integer, withAttachments As Boolean) As MailMessage
Parameters
messageNumber
- System.Int32
The message number.
withAttachments
- System.Boolean
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
Free license limitation exceeded.
PeekMessage(String)
Gets the specified message without setting the Seen flag.
public MailMessage PeekMessage(string uid)
Public Function PeekMessage(uid As String) As MailMessage
Parameters
uid
- System.String
The message id.
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
Free license limitation exceeded.
PeekMessage(String, Boolean)
Gets the specified message without setting the Seen flag.
public MailMessage PeekMessage(string uid, bool withAttachments)
Public Function PeekMessage(uid As String, withAttachments As Boolean) As MailMessage
Parameters
uid
- System.String
The message id.
withAttachments
- System.Boolean
Returns
The specified message.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
Free license limitation exceeded.
RemoveMessageFlags(Int32, IEnumerable<String>)
Removes the message flags.
public void RemoveMessageFlags(int messageNumber, IEnumerable<string> flags)
Public Sub RemoveMessageFlags(messageNumber As Integer, flags As IEnumerable(Of String))
Parameters
messageNumber
- System.Int32
The message number.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to remove.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
- System.ArgumentNullException
Flags parameter is null.
RemoveMessageFlags(Int32, String[])
Removes the message flags.
public void RemoveMessageFlags(int messageNumber, params string[] flags)
Public Sub RemoveMessageFlags(messageNumber As Integer, ParamArray flags As String())
Parameters
messageNumber
- System.Int32
The message number.
flags
- System.String[]
A collection of flags to remove.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
- System.ArgumentNullException
Flags parameter is null.
RemoveMessageFlags(String, IEnumerable<String>)
Removes the message flags.
public void RemoveMessageFlags(string uid, IEnumerable<string> flags)
Public Sub RemoveMessageFlags(uid As String, flags As IEnumerable(Of String))
Parameters
uid
- System.String
The message id.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to remove.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
- System.ArgumentNullException
Flags parameter is null.
RemoveMessageFlags(String, String[])
Removes the message flags.
public void RemoveMessageFlags(string uid, params string[] flags)
Public Sub RemoveMessageFlags(uid As String, ParamArray flags As String())
Parameters
uid
- System.String
The message id.
flags
- System.String[]
A collection of flags to remove.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
- System.ArgumentNullException
Flags parameter is null.
RemoveMessageRangeFlags(Int32, Int32, IEnumerable<String>)
Removes the flags from specified range of messages.
public void RemoveMessageRangeFlags(int startingNumber, int endingNumber, IEnumerable<string> flags)
Public Sub RemoveMessageRangeFlags(startingNumber As Integer, endingNumber As Integer, flags As IEnumerable(Of String))
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to remove.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
- System.ArgumentNullException
Flags parameter is null.
RemoveMessageRangeFlags(Int32, Int32, String[])
Removes the flags from specified range of messages.
public void RemoveMessageRangeFlags(int startingNumber, int endingNumber, params string[] flags)
Public Sub RemoveMessageRangeFlags(startingNumber As Integer, endingNumber As Integer, ParamArray flags As String())
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
flags
- System.String[]
A collection of flags to remove.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
- System.ArgumentNullException
Flags parameter is null.
RenameFolder(String, String)
Renames the folder.
public void RenameFolder(string oldName, string newName)
Public Sub RenameFolder(oldName As String, newName As String)
Parameters
oldName
- System.String
Current folder full name.
newName
- System.String
New folder full name.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
- System.ArgumentException
Old folder name is null or empty or New folder name is null or empty.
SaveMessage(Int32, Stream)
Saves the specified message to a stream.
public void SaveMessage(int messageNumber, Stream output)
Public Sub SaveMessage(messageNumber As Integer, output As Stream)
Parameters
messageNumber
- System.Int32
The message number.
output
- System.IO.Stream
The stream to save message to.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentException
Output stream is not writable.
- System.ArgumentNullException
Output stream is null.
- System.ArgumentOutOfRangeException
Message number is out of range.
Free license limitation exceeded.
SaveMessage(Int32, String)
Saves the specified message to a file.
public void SaveMessage(int messageNumber, string filePath)
Public Sub SaveMessage(messageNumber As Integer, filePath As String)
Parameters
messageNumber
- System.Int32
The message number.
filePath
- System.String
A relative or absolute path for the file where message will be saved.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
Free license limitation exceeded.
SaveMessage(String, Stream)
Saves the specified message to a stream.
public void SaveMessage(string uid, Stream output)
Public Sub SaveMessage(uid As String, output As Stream)
Parameters
uid
- System.String
The message id.
output
- System.IO.Stream
The stream to save message to.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty. or Output stream is not writable.
- System.ArgumentNullException
Output stream is null.
Free license limitation exceeded.
SaveMessage(String, String)
Saves the specified message to a file.
public void SaveMessage(string uid, string filePath)
Public Sub SaveMessage(uid As String, filePath As String)
Parameters
uid
- System.String
The message id.
filePath
- System.String
A relative or absolute path for the file where message will be saved.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
Free license limitation exceeded.
SearchMessageNumbers(String)
Searches for messages on the server that match the specified criteria.
public ReadOnlyCollection<int> SearchMessageNumbers(string query)
Public Function SearchMessageNumbers(query As String) As ReadOnlyCollection(Of Integer)
Parameters
query
- System.String
A search criteria string.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<System.Int32>
Read-only collection of message numbers that match specified criteria.
Remarks
Method executes SEARCH command against the server and returns a list of message numbers that match specified criteria. Query is constructed of one or more search keys as defined in RFC 3501 - section 6.4.4.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentException
Query is null or empty.
SearchMessageUids(String)
Searches for messages on the server that match the specified criteria.
public ReadOnlyCollection<string> SearchMessageUids(string query)
Public Function SearchMessageUids(query As String) As ReadOnlyCollection(Of String)
Parameters
query
- System.String
A search criteria string.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<System.String>
Read-only collection of message ids that match specified criteria.
Remarks
Method executes SEARCH command against the server and returns a list of message ids that match specified criteria. Query is constructed of one or more search keys as defined in RFC 3501 - section 6.4.4.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentException
Query is null or empty.
SelectFolder(String, Boolean)
Selects the specified folder.
public void SelectFolder(string name, bool readOnly)
Public Sub SelectFolder(name As String, readOnly As Boolean)
Parameters
name
- System.String
The full folder name.
readOnly
- System.Boolean
True
if folder will be selected as read-only; otherwise, false
.
Remarks
Selecting folder in read-only mode will not permit any changes of the permanent state of that folder.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
SelectInbox()
Selects INBOX folder.
Remarks
Calling this method will select folder named INBOX in read-write mode.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
SetMessageFlags(Int32, IEnumerable<String>)
Replaces all the message flags, except the \Recent flag, with the specified flags.
public void SetMessageFlags(int messageNumber, IEnumerable<string> flags)
Public Sub SetMessageFlags(messageNumber As Integer, flags As IEnumerable(Of String))
Parameters
messageNumber
- System.Int32
The message number.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to set.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
- System.ArgumentNullException
Flags parameter is null.
SetMessageFlags(Int32, String[])
Replaces all the message flags, except the \Recent flag, with the specified flags.
public void SetMessageFlags(int messageNumber, params string[] flags)
Public Sub SetMessageFlags(messageNumber As Integer, ParamArray flags As String())
Parameters
messageNumber
- System.Int32
The message number.
flags
- System.String[]
A collection of flags to set.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
- System.ArgumentNullException
Flags parameter is null.
SetMessageFlags(String, IEnumerable<String>)
Replaces all the message flags, except the \Recent flag, with the specified flags.
public void SetMessageFlags(string uid, IEnumerable<string> flags)
Public Sub SetMessageFlags(uid As String, flags As IEnumerable(Of String))
Parameters
uid
- System.String
The message id.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to set.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
- System.ArgumentNullException
Flags parameter is null.
SetMessageFlags(String, String[])
Replaces all the message flags, except the \Recent flag, with the specified flags.
public void SetMessageFlags(string uid, params string[] flags)
Public Sub SetMessageFlags(uid As String, ParamArray flags As String())
Parameters
uid
- System.String
The message id.
flags
- System.String[]
A collection of flags to set.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
- System.ArgumentNullException
Flags parameter is null.
SetMessageRangeFlags(Int32, Int32, IEnumerable<String>)
Replaces all the flags on a range of messages, except for the \Recent flag, with the specified flags.
public void SetMessageRangeFlags(int startingNumber, int endingNumber, IEnumerable<string> flags)
Public Sub SetMessageRangeFlags(startingNumber As Integer, endingNumber As Integer, flags As IEnumerable(Of String))
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
flags
- System.Collections.Generic.IEnumerable<System.String>
A collection of flags to set.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
- System.ArgumentNullException
Flags parameter is null.
SetMessageRangeFlags(Int32, Int32, String[])
Replaces all the flags on a range of messages, except for the \Recent flag, with the specified flags.
public void SetMessageRangeFlags(int startingNumber, int endingNumber, params string[] flags)
Public Sub SetMessageRangeFlags(startingNumber As Integer, endingNumber As Integer, ParamArray flags As String())
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
flags
- System.String[]
A collection of flags to set.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
- System.ArgumentNullException
Flags parameter is null.
SubscribeFolder(String)
Adds specified folder to the subscribed folders list.
Parameters
name
- System.String
The full folder name.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
- System.ArgumentException
Folder name is null or empty.
UndeleteMessage(Int32)
Undeletes the specified message.
public void UndeleteMessage(int messageNumber)
Public Sub UndeleteMessage(messageNumber As Integer)
Parameters
messageNumber
- System.Int32
The message number.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
UndeleteMessage(String)
Undeletes the specified message.
Parameters
uid
- System.String
The message id.
Exceptions
- System.InvalidOperationException
No folder is selected or UID operations are not supported or Client is not connected or Server error.
- System.ArgumentException
Message id is null or empty.
UndeleteMessageRange(Int32, Int32)
Undeletes the specified messages.
public void UndeleteMessageRange(int startingNumber, int endingNumber)
Public Sub UndeleteMessageRange(startingNumber As Integer, endingNumber As Integer)
Parameters
startingNumber
- System.Int32
First message number.
endingNumber
- System.Int32
Last message number.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Starting number is out of range or Ending number is out of range.
UndeleteMessages()
Undeletes all the messages marked for deletion.
Exceptions
- System.InvalidOperationException
No folder is selected or Client is not connected or Server error.
- System.ArgumentOutOfRangeException
Message number is out of range.
UnsubscribeFolder(String)
Removes specified folder the from subscribed folders list.
Parameters
name
- System.String
The full folder name.
Exceptions
- System.InvalidOperationException
Client is not connected or Server error.
- System.ArgumentException
Folder name is null or empty.
Events
Terminated
Occurs when connection with server is terminated.
public event EventHandler<TerminatedEventArgs> Terminated
Public Event Terminated As EventHandler(Of TerminatedEventArgs)
Event Type
- System.EventHandler<TerminatedEventArgs>
Remarks
This event is raised when connection with server is improperly terminated due to inactivity or some other reason. Client will close and dispose its internal stream so there is no need for calling Disconnect() method.