Retrieves the mail message with the specified unique identifier (UID) using the specified
fetch-option.
Namespace: S22.ImapAssembly: S22.Imap (in S22.Imap.dll) Version: 3.6.0.0 (3.6.0.0)
Syntax
C# |
---|
MailMessage GetMessage( uint uid, FetchOptions options, bool seen = true, string mailbox = null ) |
Parameters
- uid
- Type: System..::..UInt32
The unique identifier of the mail message to retrieve.
- options
- Type: S22.Imap..::..FetchOptions
A value from the FetchOptions enumeration which allows for fetching selective parts of a mail message.
- seen (Optional)
- Type: System..::..Boolean
Set this to true to set the \Seen flag for this message on the server.
- mailbox (Optional)
- Type: System..::..String
The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on.
Return Value
An initialized instance of the MailMessage class representing the fetched mail message.
Remarks
A unique identifier (UID) is a 32-bit value assigned to each message which uniquely
identifies the message within the respective mailbox. No two messages in a mailbox share
the same UID.
If you need more fine-grained control over which parts of a mail message to fetch, consider using one of the overloaded GetMessage methods.
Examples
This example demonstrates how to fetch only the mail message headers of
a mail message, instead of the entire message.
CopyC#

ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages in the mailbox that have "Hello" in the subject. IEnumerable<uint> uids = Client.Search( SearchCondition.Subject("Hello") ); // Fetch the mail headers of the first message and print it's subject line. if(uids.Count() > 0) { MailMessage msg = Client.GetMessage(uids.First(), FetchOptions.HeadersOnly); Console.WriteLine("Subject: " + msg.Subject); } Client.Dispose();
Exceptions
Exception | Condition |
---|---|
S22.Imap..::..BadServerResponseException | The mail message could not be fetched. The message property of the exception contains the error message returned by the server. |
System..::..ObjectDisposedException | The ImapClient object has been disposed. |
System.IO..::..IOException | There was a failure writing to or reading from the network. |
S22.Imap..::..NotAuthenticatedException | The method was called in non-authenticated state, i.e. before logging in. |