Retrieves a mail message from the POP3 server.

Namespace: S22.Pop3
Assembly: S22.Pop3 (in S22.Pop3.dll) Version: 1.1.4653.26443 (1.1.0.0)

Syntax

C#
public MailMessage GetMessage(
	uint number,
	FetchOptions options = FetchOptions.Normal,
	bool delete = false
)

Parameters

number
Type: System..::..UInt32
The message number of the mail message to retrieve
options (Optional)
Type: S22.Pop3..::..FetchOptions
A value from the FetchOptions enumeration which allows for fetching selective parts of a mail message.
delete (Optional)
Type: System..::..Boolean
Set this to true to delete the message on the server after it has been retrieved.

Return Value

An initialized instance of the MailMessage class representing the fetched mail message

Examples

CopyC#
Pop3Client Client = new Pop3Client("pop.gmail.com", 995, "My_Username",
    "My_Password", true, AuthMethod.Login);

MessageInfo[] info = Client.GetStatus();

/* download the first message and print its subject line */
if(info.Length > 0)
{
    MailMessage message = Client.GetMessage(info[0].Number);
    Console.WriteLine("Subject: " + message.Subject);
}

Client.Dispose();

Examples

This example demonstrates how to retrieve only the mail message headers of a mail message, instead of retrieving the entire message.
CopyC#
Pop3Client Client = new Pop3Client("pop.gmail.com", 995, "My_Username",
    "My_Password", true, AuthMethod.Login);

MessageInfo[] info = Client.GetStatus();

/* download the first message's headers and print its subject line */
if(info.Length > 0)
{
    MailMessage message = Client.GetMessage(info[0].Number, FetchOptions.HeadersOnly);
    Console.WriteLine("Subject: " + message.Subject);
}

Client.Dispose();

Exceptions

ExceptionCondition
S22.Pop3..::..NotAuthenticatedExceptionThrown if the method was called in a non-authenticated state, i.e. before logging into the server with valid credentials.
S22.Pop3..::..BadServerResponseExceptionThrown if the mail message could not be retrieved. The message property of the exception contains the error message returned by the server.

See Also