MailMessageLoadMessage Method (Byte) |
Namespace: MailBee.Mime
Exception | Condition |
---|---|
MailBeeInvalidArgumentException | rawData is a null reference (Nothing in Visual Basic). |
MailBeeDataParsingException | Outlook .MSG file is being loaded instead of MIME (.EML) and ThrowExceptions is true. |
The MIME source of the message is the contents of .EML file (which you can import with LoadMessage(String) method).
To get an existing message as a byte array, use GetMessageRawData method.
Note |
---|
This method can change the contents of the source byte array. This may only occur in extremely rare case when line endings in there are single CR characters rather than CRLF pairs (correct endings) or single LF characters (incorrect but widely used). In this case, MailBee normalizes the data by replacing single CRs with LFs (not changing the length of the array). If for some reason you want to preserve the source data intact, make a copy of the source array before passing it to this method. To avoid unnecessary memory consumption, you can first check if the message data indeed contains CR line endings, and make a copy of the data only in this rare case. |
// 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);