hMailServer - server scripts - trigger external DLL function?

1.6k Views Asked by At

maybe it is a dummy question and there exists better approaches, but I wonder if there is any possibility of catching an event on incoming email using server side script and inside that script would be external DLL call or script which connect to database and writes some metadata from incoming message (same as external DLL would)?

The scenario could be:

  1. Message is coming to hMailServer from sender
  2. Some trigger starts
  3. Trigger calls function in external DLL which would parse the email body a writes data about recipient, subject, message perex and attachment count to special database table for speedlisting and email notification purposes which could be located in the same database as hmailserver
  4. let the message to be delivered

Goal: to have instant information about all emails containing from, to, subject, message perex(first 100 chars), attachments flag and read flag accessible through SQL query without having to connect to IMAP or PO3. So using one SQL query I can get all notifications for all accounts and send them through signalR.

I realised that in MS SQL database of hmailserver is table called hm_messages which is automatically filled when email arrives but contains no subject, mostly no sender and definitely no body and attachment count. Row in that table contains only information about account, folder, flags, dates and name of *.eml file. I could write a trigger with SQLCLR function which could do the same as mentioned above but even if I have *.eml file name I do not have its actual location on the hard drive. So I am back to square one.

Otherwise I have to download messages from all accounts in a time loop, which is stealing my server CPU and memory especially where there is about 60 email accounts and thousands of messages in them and have to iterate them all over.

2

There are 2 best solutions below

4
On BEST ANSWER

hMailServer supports scripting in VBScript/JScript and supplies events to indicate new message arrival.

Both scripting languages support COM so can use for example ADO to connect to a database or can interoperate with a (late bound) COM Visible .Net assembly.

So yes, it can do what you ask but I would think carefully about the scalability of doing this

0
On

As you found out your self, you can use VB-Script and JScript to run hMailServer specific Events, invoked by C:\Program Files (x86)\hMailServer\Events\EventHandlers.vbs

You also can use any COM/DCOM Language or Toolkit which can access Microsoft COM Technology. hMailServers Main Server Object is a OutOfProcess Server which supports late binding and Typelib based late access.

To use it via Runtime binding you can just call any hMailServer COM API Object with VB-Script. If you want to access hMailServer by C#.NET or VB.NET or native C/C++ you need to import hMailServers Typelibe (hMailServer.tlb it hMailServer \bin folder)

Examples how you can access hMailServer from C# and other Languages can be found in the following Articles:

C#.NET https://www.hmailserver.com/forum/viewtopic.php?f=21&t=31507

VB.NET https://www.hmailserver.com/forum/viewtopic.php?f=21&t=31508

Native C/C++ (Win32/Win64) https://www.hmailserver.com/forum/viewtopic.php?f=21&t=31510

COM-API Documentation https://www.hmailserver.com/documentation/latest/?page=com_objects

Required tools: Visual Studio 2013 but not earlier and not above.