MailBee.NET Objects 3.1

MailMessage.Clone Method 

Creates a copy of the message.

public MailMessage Clone();

Return Value

A MailMessage object which represents the cloned message.

Remarks

The deep clone is performed, that means the fully independent copy of the message is created and there are no shared objects between the original message and its copy.

Example

This sample demostrates that the message copy created by this method has its own copies of all internal objects. For instance, their Attachments collections are another objects, not just two references to the same object.

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

class Sample
{
    static void Main(string[] args)
    {
        // Load the message from file.
        MailMessage msg = new MailMessage();
        msg.LoadMessage(@"C:\Docs\TestMail.eml");

        MailMessage newMsg = msg;
        MailMessage clonedMsg = msg.Clone();

        // Check if the attachments of two messages are equal
        // and display the corresponding notification.
        if (msg.Attachments == newMsg.Attachments)
        {
            Console.WriteLine("Equals");
        }
        else
        {
            Console.WriteLine("Not equals");
        }

        // Check if the attachments of two messages are equal
        // and display the corresponding notification.
        if (msg.Attachments == clonedMsg.Attachments)
        {
            Console.WriteLine("Equals");
        }
        else
        {
            Console.WriteLine("Not equals");
        }
    }
}

// Output:
// Equals
// Not equals
[Visual Basic]
Imports MailBee
Imports MailBee.Mime

Module Sample
    Sub Main(ByVal args As String())
        ' Load the message from file.
        Dim msg As New MailMessage
        msg.LoadMessage("C:\Docs\TestMail.eml")

        Dim newMsg = msg
        Dim cloneMsg = msg.Clone()

        ' Check if the attachments of two messages are equal
        ' and display the corresponding notification.
        If msg.Attachments Is newMsg.Attachments Then
            Console.WriteLine("Equals")
        Else
            Console.WriteLine("Not equals")
        End If

        ' Check if the attachments of two messages are equal
        ' and display the corresponding notification.
        If msg.Attachments Is cloneMsg.Attachments Then
            Console.WriteLine("Equals")
        Else
            Console.WriteLine("Not equals")
        End If
    End Sub
End Module

' Output:
' Equals
' Not equals

See Also

MailMessage Class | MailBee.Mime Namespace