MailBee.NET Objects 4.0

MailMessage.SaveMessage Method (Stream)

Saves a message into the specified stream.

public bool SaveMessage(
   Stream stream
);

Parameters

stream
The stream where the message should be saved.

Return Value

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

Remarks

The stream should already be opened for reading before this method can be called.

The developer can use LoadMessage method to load the previously saved message.

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptionstream is a null reference (Nothing in Visual Basic).
MailBeeStreamExceptionThe given stream does not support writing or stream I/O error occurred, and ThrowExceptions is true.

Example

This sample loads the message from .EML file and saves it into the stream.

[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).
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");
using (FileStream fs = new FileStream(@"C:\Temp\msg.eml", FileMode.CreateNew))
{
    msg.SaveMessage(fs);
}
[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 msg As New MailMessage
msg.LoadMessage("C:\Docs\TestMail.eml")
Dim fs As FileStream
Try
    fs = New FileStream("C:\Temp\msg.eml", FileMode.CreateNew)
    msg.SaveMessage(fs)
Finally
    If Not fs Is Nothing Then
        fs.Close()
    End If
End Try

See Also

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