Adds a block of bytes to the source of the message.
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 method. Or, if you're using streams, use LoadMessage overload.
To assembly a message which naturally comes as a series of smaller e-mail messages (also called partial messages), use AppendPartialMessage method.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | nextChunk is a null reference (Nothing in Visual Basic). |
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 In real world applications, it's easier to load a message from a file/stream/memory using LoadMessage method and its overloads.
[C#] 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); } }
[Visual Basic] Imports System Imports System.IO Imports MailBee Imports MailBee.Mime Module Sample Sub Main(ByVal args As String()) Dim msg = New MailMessage Dim filename As String = "C:\Docs\TestMail1.eml" Dim fs As FileStream Try ' Open the file for reading. fs = New FileStream(filename, FileMode.Open) ' Create a 100 bytes buffer. Dim bytes As Byte() ReDim bytes(100) For i As Integer = 1 To 10 ' 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) Next Finally If Not fs Is Nothing Then fs.Close() End If End Try ' The message will be parsed at this point (when we access any of its properties). Console.WriteLine(msg.Subject) End Sub End Module
MailMessage Class | MailBee.Mime Namespace | AppendPartialMessage