Stores the specified mail message on the IMAP server.

Namespace: S22.Imap
Assembly: S22.Imap (in S22.Imap.dll) Version: 3.6.0.0 (3.6.0.0)

Syntax

C#
uint StoreMessage(
	MailMessage message,
	bool seen = false,
	string mailbox = null
)

Parameters

message
Type: System.Net.Mail..::..MailMessage
The mail message to store on the server.
seen (Optional)
Type: System..::..Boolean
Set this to true to set the \Seen flag for the message on the server.
mailbox (Optional)
Type: System..::..String
The mailbox the message will be stored in. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to store the message in.

Return Value

The unique identifier (UID) of the stored 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.

Examples

This example demonstrates how to store a mail message on an IMAP server.
CopyC#
ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe",
"My_Password", true, AuthMethod.Login);

MailMessage message = CreateSimpleMailMessage();
uint uid = Client.StoreMessage(message);

Console.WriteLine("The UID of the stored mail message is " + uid);

Client.Dispose();

// ...........

// This creates a simple mail message with a text/plain body and a PNG image
// as a file attachment.
// Consult the MSDN website for more details on the System.Net.Mail.Mailmessage class.
static MailMessage CreateSimpleMailMessage() {
    MailMessage message = new MailMessage();

    message.From = new MailAddress("someone@someplace.com");
    message.To.Add("john.doe@someplace.com");

    message.Subject = "This is just a test!";
    message.Body = "This is the text/plain body. An additional HTML body " +
        "can optionally be attached as an alternate view";

    // Add the attachment.
    Attachment attachment = new Attachment("some_image.png", "image/png");
    attachment.Name = "my_attached_image.png";
    message.Attachments.Add(attachment);

    return message;
}

Exceptions

ExceptionCondition
System..::..ArgumentNullExceptionThe message parameter is null.
S22.Imap..::..BadServerResponseExceptionThe mail message could not be stored. The message property of the exception contains the error message returned by the server.
System..::..ObjectDisposedExceptionThe ImapClient object has been disposed.
System.IO..::..IOExceptionThere was a failure writing to or reading from the network.
S22.Imap..::..NotAuthenticatedExceptionThe method was called in non-authenticated state, i.e. before logging in.

See Also