MailBee.NET Objects 3.1

MailMessage.LoadMessage Method (Byte[])

Loads the message from a byte array.

public bool LoadMessage(
   byte[] rawData
);

Parameters

rawData
The byte array containing the MIME source of the message.

Return Value

true if the message was successfully loaded; otherwise, false.

Remarks

The MIME source of the message is the contents of .EML file (which you can import with LoadMessage method).

To get an existing message as a byte array, use GetMessageRawData method.

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptionrawData is a null reference (Nothing in Visual Basic).

Example

This sample loads the message from a byte array and displays the subject of the message. Reading from a stream is used for demonstration purposes only. In real-world apps, it's easier to use LoadMessage method to load a message from a file.

[C#]
// To use the code below, import these namespaces at the top of your code.
using System.IO;
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class).
byte[] msgBytes = null;
using (BinaryReader br = new BinaryReader(File.OpenRead(@"C:\Docs\TestMail.eml")))
{
    FileInfo fi = new FileInfo(@"C:\Docs\TestMail.eml");
    msgBytes = br.ReadBytes((int)fi.Length);
}
MailMessage msg = new MailMessage();
msg.LoadMessage(msgBytes);
Console.WriteLine(msg.Subject);
[Visual Basic]
' To use the code below, import these namespaces at the top of your code.
Imports System.IO
Imports MailBee
Imports MailBee.Mime

' The actual code (put it into a method of your class).
Dim msgBytes As Byte() = Nothing

Dim br As BinaryReader
Try
    br = New BinaryReader(File.OpenRead("C:\Docs\TestMail.eml"))
    Dim fi As New FileInfo("C:\Docs\TestMail.eml")
    msgBytes = br.ReadBytes(fi.Length)
Finally
    If Not br Is Nothing Then
        br.Close()
    End If
End Try

Dim msg As New MailMessage
msg.LoadMessage(msgBytes)
Console.WriteLine(msg.Subject)

See Also

MailMessage Class | MailBee.Mime Namespace | MailMessage.LoadMessage Overload List | GetMessageRawData