ImapUploadMessage Method (MailMessage, String)
Uploads a mail message to the specified folder.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public bool UploadMessage(
	MailMessage msg,
	string folderName
)

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.

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. For uploaded messages, the mail server automatically assigns "\Recent" flag. The date of receiving the message by the server (INTERNALDATE in IMAP4 terms) will be set to the current datetime/timezone of the local computer (not the mail server).

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 (see UploadMessage(MailMessage, String, SystemMessageFlags) sample).

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).

Examples

This sample loads the message from a file and uploads it into "Archive" folder.

The sample assumes "Archive" folder had already been created in the past. To learn how to make sure the folder exists, see UploadMessage(MailMessage, String, String, DateTime) or UploadMessage(MailMessage, String, String, String) samples.

using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;

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

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

        // Load the message from C:\Temp\message.eml file.
        MailMessage msg = new MailMessage();
        msg.LoadMessage(@"C:\Temp\message.eml");

        // Upload the message into "Archive" folder.
        imp.UploadMessage(msg, "Archive");

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