Dynamicweb 8 Documentation
MessagingHandler Constructor(Message,RecipientCollection,CallbackHandler)
Example 

The Message to handle.
The recipients to handle.
The callback handler to use in this context.
Creates a new instance of the messaging handler. This constructor can be used wither when starting a new send process or when resuming. When resuming, the recipients argument can be null.
Syntax
'Declaration
 
Public Function New( _ 
   ByVal message As Message, _ 
   ByVal recipients As RecipientCollection, _ 
   ByVal callbackHandler As CallbackHandler _ 
)
public MessagingHandler( 
   Message message,
   RecipientCollection recipients,
   CallbackHandler callbackHandler 
)

Parameters

message
The Message to handle.
recipients
The recipients to handle.
callbackHandler
The callback handler to use in this context.
Example
Working with the Callback HandlerWorking with the Callback Handler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dynamicweb.Examples.CSharp.EmailMessaging
{
    class UsingCallbackHandlerSample
    {
        public void SendWithCallbackHandler()
        {
            //Create a recipient collection and add recipient
            var recipients = new Dynamicweb.EmailMessaging.RecipientCollection();
            var recipient = new Dynamicweb.EmailMessaging.Recipient();
            recipient.Name = "Test";
            recipient.EmailAddress = "test12@testdomain.tld";
            recipients.Add(recipient);

            //Get a message with a specific id.
            var message = Dynamicweb.EmailMessaging.Message.GetMessageById(20);

            //Instanciate a new message handler.
            //This will use the TestCallbackHandler, which will alter the process.
            var handler = new Dynamicweb.EmailMessaging.MessagingHandler(message, recipients, new TestCallbackHandler());

            //Start the send process.
            var processStarted = handler.Process();

            if (!processStarted)
                throw new Exception("Unable to start process");
        }

    }

    class TestCallbackHandler : Dynamicweb.EmailMessaging.CallbackHandler
    {
        //This is one of the methods you can override in the CallbackHandler class.
        public override void OnBeforeDelivery(Dynamicweb.EmailMessaging.CallbackHandlerContext context, Dynamicweb.EmailMessaging.Message message, Dynamicweb.EmailMessaging.Recipient recipient, Dynamicweb.EmailMessaging.MessageDeliverer deliverer, System.Net.Mail.MailMessage mailMessage)
        {
            //Imagine you want to change the way a message is delivered for a specific message and recipient.

            //Do the check
            if (message.Id == 20 && recipient.EmailAddress == "test12@testdomain.tld")
            {
                //Set the new delivery provider
                deliverer.DeliveryProvider = new TestDeliveryProvider();
            }
        }
    }
    class TestDeliveryProvider : Dynamicweb.EmailMessaging.MessageDeliveryProvider
    {
        public override bool Deliver(System.Net.Mail.MailMessage mailMessage)
        {
            //This is just a simple implementation using the Dynamicweb EmailHandler system.
            //This could also be an external system that can send an System.Net.Mail.MailMessage.
            return Dynamicweb.EmailHandler.Send(mailMessage);
        }
    }
}
Public Class UsingCallbackHandlerSample

    Public Sub SendWithCallbackHandler()
        'Create a recipient collection and add recipient
        Dim recipients As New Global.Dynamicweb.EmailMessaging.RecipientCollection()
        Dim recipient As New Global.Dynamicweb.EmailMessaging.Recipient()
        recipient.Name = "Test"
        recipient.EmailAddress = "test12@testdomain.tld"
        recipients.Add(recipient)

        'Get a message with a specific id.
        Dim message As Global.Dynamicweb.EmailMessaging.Message = Global.Dynamicweb.EmailMessaging.Message.GetMessageById(20)

        'Instanciate a new message handler.
        'This will use the TestCallbackHandler, which will alter the process.
        Dim handler As New Global.Dynamicweb.EmailMessaging.MessagingHandler(message, recipients, New TestCallbackHandler())

        'Start the send process.
        Dim processStarted As Boolean = handler.Process()

        If Not processStarted Then
            Throw New Exception("Unable to start process")
        End If
    End Sub

End Class

Public Class TestCallbackHandler
    Inherits Global.Dynamicweb.EmailMessaging.CallbackHandler

    'This is one of the methods you can override in the CallbackHandler class.
    Public Overrides Sub OnBeforeDelivery(context As EmailMessaging.CallbackHandlerContext, message As EmailMessaging.Message, recipient As EmailMessaging.Recipient, deliverer As EmailMessaging.MessageDeliverer, mailMessage As System.Net.Mail.MailMessage)
        'Imagine you want to change the way a message is delivered for a specific message and recipient.

        'Do the check
        If message.Id = 20 AndAlso recipient.EmailAddress = "test12@testdomain.tld" Then
            'Set the new delivery provider
            deliverer.DeliveryProvider = New TestDeliveryProvider()
        End If
    End Sub
End Class

Public Class TestDeliveryProvider
    Inherits Global.Dynamicweb.EmailMessaging.MessageDeliveryProvider

    Public Overrides Function Deliver(mailMessage As System.Net.Mail.MailMessage) As Boolean
        'This is just a simple implementation using the Dynamicweb EmailHandler system.
        'This could also be an external system that can send an System.Net.Mail.MailMessage.
        Return Global.Dynamicweb.EmailHandler.Send(mailMessage)
    End Function
End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

MessagingHandler Class
MessagingHandler Members
Overload List

Send Feedback