ImapUploadMessage Method (MailMessage, String, String, DateTime)
Uploads a mail message to the specified folder and assigns the specified date and flags to this message.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public bool UploadMessage(
	MailMessage msg,
	string folderName,
	string flags,
	DateTime dt
)

Parameters

msg
Type: MailBee.MimeMailMessage
A reference to the MailMessage object representing the message to be uploaded.
folderName
Type: SystemString
The full name of the folder to upload the message to.
flags
Type: SystemString
The string containing the message flags (in IMAP4 format) to be assigned to the message, or a null reference (Nothing in Visual Basic) to set default flags at the discretion of the server.
dt
Type: SystemDateTime
The datetime to be assigned to the INTERNALDATE attribute of the message (the date of receiving the message by the server). If MinValue, the server will assign this date itself.

Return Value

Type: Boolean
true if the message was uploaded successfully; otherwise, false.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks

This method implements APPEND command of the IMAP4 protocol.

To upload a file, the developer can first load it into MailMessage object using LoadMessage(String) method, and then call UploadMessage(MailMessage, String, String, String, Boolean, UidPlusResult) passing a reference to this MailMessage object. There is no extra overhead on parsing the message since LoadMessage(String) just reads a file into memory. The MailMessage won't parse the contained message unless the application starts accessing its properties or methods (so-called "lazy" model).

To upload a mail message just sent using Smtp component, the developer call UploadMessage(MailMessage, String, String, String, Boolean, UidPlusResult) method passing a reference to the Message property.

To obtain the UID value assigned to the uploaded message, the developer should either examine DestUidString property of UidPlusResult object passed in res parameter of UploadMessage(MailMessage, String, String, String, Boolean, UidPlusResult) method (the server must support UIDPLUS capability), or obtain UidNext value calling GetFolderStatus(String) method before making upload (this approach is compatible with all servers).

To get standard message flags as string in IMAP4 format (e.g. "\Seen \Flagged"), the developer can use SystemFlagsToString(SystemMessageFlags) method.

In addition to the flags specified by the application, the server also sets "\Recent" flag. Thus, the uploaded message will always have at least "\Recent" flag set.

Examples
This sample creates a new mail message and saves it into "Draft" folder (creating the folder if necessary) assigning the current datetime/timezone of the local computer and setting "\Draft" flag. Also, the server will implicitly add "\Recent" flag.
using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server and log in the account.
        imp.Connect("imap4.company.com");
        imp.Login("jdoe", "secret");

        // Create a new message. Assume we need to save a draft of the message.
        MailMessage msg = new MailMessage();

        // Create Draft folder if needed.
        FolderCollection folders = imp.DownloadFolders(false, null, "Draft");
        if (folders.Count == 0)
        {
            imp.CreateFolder("Draft");
        }

        // Upload the message and assign the current datetime and timezone
        // of the client as the date of receiving the message by the server
        // (INTERNALDATE in IMAP4 terms). 
        // "\Draft" string is set directly. Alternatively, we could have
        // used MessageFlagSet.SystemFlagsToString(SystemMessageFlags.Draft);
        imp.UploadMessage(msg, "Draft", @"\Draft", DateTime.Now);

        // Disconnect from the server.
        imp.Disconnect();
    }
}
See Also