MailBee.NET Objects 3.1

MailMessage.AppendPartialMessage Method 

Adds the specified partial message to this message.

public bool AppendPartialMessage(
   MailMessage nextPart
);

Parameters

nextPart
A portion of the message as another MailMessage object.

Return Value

true if the partial message which was appended was the last one required; otherwise, false.

Remarks

Some mail client programs can split large messages into a number of smaller messages before sending and then send these smaller e-mails separately. This technique was used to overcome limitations of maximum size of a message which existed on some mail servers. Nowdays, this practice is not used but MailBee is still capable of parsing such messages. To assembly a message from its parts (they have message/partial in their ContentType), you should get the first part (having PartIndex set to 1), and append the remaining messages in the correct order (with PartIndex set to 2, 3, etc) using AppendPartialMessage until it returns true. AppendPartialMessage returns true when you append a message having PartIndex equal to PartCount.

Use PartCount property to determine if the mail message is split (and so it's needed to get the remaining parts and join them with AppendPartialMessage method).

Use PartIndex property to obtain the index of the message so that you would be able to pass the messages to be appended by AppendPartialMessage method in proper order (from 1 to PartCount).

Exceptions

Exception TypeCondition
MailBeeInvalidArgumentExceptionnextPart is a null reference (Nothing in Visual Basic) or not a partial message.
MailBeeInvalidStateExceptionThe message is not partial, so another partial message can't be added to it.

Example

This sample assemblies the message from 4 partial messages. It loads the first portion and then calls AppendPartialMessage for the remaining 3 portions.

[C#]
using MailBee;
using MailBee.Mime;

class Sample
{
    static void Main(string[] args)
    {
        MailMessage newMsg = new MailMessage();
        MailMessage partialMsg = new MailMessage();
        newMsg.LoadMessage(@"C:\Docs\splitmail\1of4.eml");

        // Append 3 partial messages that are loaded from disk.
        for (int i = 2; i <= 4; i++)
        {
            partialMsg.LoadMessage(string.Format(@"C:\Docs\splitmail\{0}of4.eml", i));
            newMsg.AppendPartialMessage(partialMsg);
        }

        // Save the entire message to disk.
        newMsg.SaveMessage(@"C:\Temp\entire.eml");
    }
}
[Visual Basic]
Imports MailBee
Imports MailBee.Mime

Module Sample
    Sub Main(ByVal args As String())
        Dim newMsg = New MailMessage
        Dim partialMsg = New MailMessage
        newMsg.LoadMessage("C:\Docs\splitmail\1of4.eml")

        ' Append 3 partial messages that are loaded from disk.
        For i As Integer = 2 To 4
            partialMsg.LoadMessage(String.Format("C:\Docs\splitmail\{0}of4.eml", i))
            newMsg.AppendPartialMessage(partialMsg)
        Next

        ' Save the entire message to disk.
        newMsg.SaveMessage("C:\Temp\entire.eml")
    End Sub
End Module

See Also

MailMessage Class | MailBee.Mime Namespace | PartIndex | PartCount | IsEntire