MailMessageAppendChunk Method
Adds a block of bytes to the source of the message.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public void AppendChunk(
	byte[] nextChunk
)

Parameters

nextChunk
Type: SystemByte
A reference to the byte array containing a portion of message data.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionnextChunk is a null reference (Nothing in Visual Basic).
Remarks

This method can be used to assemble a message from smaller memory blocks (for instance, if the message is being read from the resource which cannot return all the data at once). However, since this method recreates the internal message data buffer on each call, it should be used only if the size of the data is not known until all the data received. If the size of the data is known from the very beginning, it's more effective to create a memory array of the required length, fill it with the data and then pass this array to LoadMessage(Byte) method. Or, if you're using streams, use LoadMessage(Stream) overload.

To assembly a message which naturally comes as a series of smaller e-mail messages (also called partial messages), use AppendPartialMessage(MailMessage) method.

Examples
This sample demonstrates loading 1000 bytes of the message data from a file using a buffer of a fixed length (100 bytes). It's assumed the file is at least 1000 bytes in size.
Note Note

In real world applications, it's easier to load a message from a file/stream/memory using LoadMessage(String) method and its overloads.

Also, real world apps shouldn't rely on the fact that FileStream.Read method of .NET framework always returns the requested number of bytes. They should rather check its return value and repeat reading attempt if the number of bytes read was less than requested. The code snippet in FileStream.Read topic in MSDN shows how this can be done.

using System;
using System.IO;
using MailBee;
using MailBee.Mime;

class Sample
{
    static void Main(string[] args)
    {
        MailMessage msg = new MailMessage();
        string filename = @"C:\Docs\TestMail.eml";

        // Open the file for reading.
        using (FileStream fs = new FileStream(filename, FileMode.Open))
        {
            // Create a 100 bytes buffer.
            byte[] bytes = new byte[100];

            for (int i = 0; i < 10; i++)
            {
                // Read a portion of data (100 bytes) from the file and append it to the message source.
                fs.Read(bytes, i * bytes.Length, bytes.Length);
                msg.AppendChunk(bytes);
            }
        }

        // The message will be parsed at this point (when we access any of its properties).
        Console.WriteLine(msg.Subject);
    }
}
See Also