How To Use Axon In Your Own DNN Modules

Axon is designed to be used by external applications or other modules, allowing you to use the robust email processing engine in Axon for all of your email needs in your own modules and applications. To control Axon from your own module , add a reference to the core OnyakTech.Axon.dll assembly. Once you do this, you will have access to all of the core functionality in Axon. Most of what you will need is in the OnyakTech.Axon.CampaignEngine class. This class contains methods specifically created for use by external modules.

To work with a Campaign, create an instance of the CampaignEngine class and pass the ID of the Campaign you want to work with as a parameter to the constructor of this class. Once the class is initialized, you can easily run batches, execute a new run, get a list of current runs, etc. You can even use Axon for rendering the content and have it returned to you for display in your modules or email it through your application.

Send Axon Emails based on the Email Address

The following sample code will open campaign, process the content based on the email address you provide (this will render any dynamic content into the email body you have setup in the Campaign for the email address.  For example, if you have added dynamic content in your campaign that displays a users current orders, subscription levels or attached a PDF report with information specific to a user, Axon will match the email address you provided with a user registered in your DNN web site and then fill in all of the dynamic content that relates to that user.)

 

objCampaign = objCampController.GetItem(1)

'If you want to set the recipients list dynamically, you will need to change that now and then save
'the changes, otherwise you could just bypass this and go right to the CampaignEngine
objCampaign.FixedList = "somebody@domain.com;"'Set the recipients into the Fixed List
objCampController.Update(objCampaign)' Save changes

Dim AxonEngine As AxonEngine.Execute()' Calling the Execute method will send the emails

 

Obtain Processed Email Body HTML


Another approach is to call the PreviewRun function passing the email address as a parameter.  This will return the email body contents as HTML that you can then display in your module or send it.  Using this method you won't need to set the FixedList since Axon ignores the campaign recipients and processes the email content based on the email address you pass in the parameter. 

Dim strEmailBodyHTML As String
Dim AxonEngine As New OnyakTech.Axon.CampaignEngine(objCampaign.CampaignSystemID,)
strEmailBodyHTML = AxonEngine.PreviewRun("somebody@domain.com")' Returns the HTML for the email


Multithreaded Execution


If you would like to execute a campaign that may contain over 100,000 recipients, you will want to submit the campaign for execution in it's own thread and then check it's progress.

Dim AxonRun As CampaignEngine
AxonRun = New CampaignEngine(CampaignSystemID, True)
thr = New System.Threading.ThreadAddressOf AxonRun .Execute)
thr.Start()

The code above will process the campaign in a new thread.  At set intervals, you can then check it's progress by looking at the StopExecution property as shown below.

If CampaignEngine.workerStatus= True Then
'Campaign has completed it's run.
Else
'Campaign is still running.
lblStatus.Text = "Progress: (" & CampaignEngine.EmailSentCount & " out of " & CampaignEngine.EmailToSendCount & " emails sent)"
End If

 

Cancel Execution


If you need to stop a run, set the Stop Execution property to True.  Example: CampaignEngine.StopExecution = True

Summary


Axon provides everything you will need to create and send emails with dynamic content.  For a complete list of all available methods, take a look at the Axon namespace in the Object Browser in Visual Studio. Additional methods are listed below that you can call from your own module.

ExecuteInboxMessageProcessor() : Runs all POP3 Related functions of Axon.   Executes the Auto Response Campaigns, List Server Campaigns, Unsubscribers and Non-Delivery Reports.

 

ExecuteThreads() : Runs all campaigns of type Threaded.

WorkerStatusInfo : Property that contains detailed information about the current execution.

EmailSentCount : Property that contains the total number of emails sent during the current execution.

EmailToSendCount : Property that contains the total number of recipients.

StartTime : Property that contains the date and time the execution started.