MailBee.NET Objects 6.0

MailMessage.GetMessageRawData Method 

Gets the source of the message as a byte array.

public byte[] GetMessageRawData();

Return Value

A byte array representing the MIME source of the message.

Remarks

To get only a header section of the message, use RawHeader property. To save the message to disk or into a stream, use SaveMessage method.

Example

This sample saves the MIME source of the message into .EML file for demonstration purposes only. Real-world applications should use SaveMessage method for this.

[C#]
using System.IO;
using MailBee;
using MailBee.Pop3Mail;
using MailBee.Mime;

class Sample
{
    static void Main(string[] args)
    {
        // Download the first mail message from the specified POP3 account.
        MailMessage msg = Pop3.QuickDownloadMessage("mail.company.com", "jdoe", "password", 1);

        // Save message as .EML file.
        using (BinaryWriter bw = new BinaryWriter(File.Open(@"C:\Temp\msg.eml",
            FileMode.OpenOrCreate)))
        {
            bw.Write(msg.GetMessageRawData());
        }
    }
}
[Visual Basic]
Imports System.IO
Imports MailBee
Imports MailBee.Pop3Mail
Imports MailBee.Mime

Module Sample
    Sub Main(ByVal args As String())
        ' Download the first mail message from the specified POP3 account.
        Dim msg As MailMessage = Pop3.QuickDownloadMessage("mail.company.com", "jdoe", "password", 1)

        ' Save message as .EML file.
        Dim bw As BinaryWriter
        Try
            bw = New BinaryWriter(File.Open("C:\Temp\msg.eml", FileMode.OpenOrCreate))
            bw.Write(msg.GetMessageRawData())
        Finally
            If Not bw Is Nothing Then
                bw.Close()
            End If
        End Try
    End Sub
End Module

See Also

MailMessage Class | MailBee.Mime Namespace