Indy IMAP Client Email Notification (Delphi 2009)

I am working on a deamon application that uses an email inbox as an input queue. The response time should be as high as possible if the server overhead is minimal, therefore, polling an e-mail mailbox is out of the question. Because IMAP allows you to receive notifications of new emails, this is ideal for the application.

However, I ran into difficulties when I tried to implement this mechanism in a Delphi / Indy application. TIdIMAP4 works fine (besides some Unicode issues that are not relevant to my case), but I could not find a way to implement notifications in it.

This should be a simple GIYF problem, but for some unknown reason, I cannot find ANY relevant information about Indy components when searching the Internet.

A solution or alternative approaches would be deeply appreciated.

Edit: since Indy does not support asynchronous email notifications, does anyone know which free components for delphi could enable this.

+4
source share
4 answers

TIdIMAP4 does not support receiving asynchronous notifications, such as notification of new messages. This will require a change in the TIdIMAP4 implementation for a multi-threaded model similar to that used by TIdTelnet, but more complex due to the TIdIMAP4 I / O model. At this point, you should periodically poll mailboxes.

+4
source

Why not make the application an smtp server, not a client.

Thus, you have a direct notification, since the letter is sent directly to your application, instead of pulling out a new letter.

There are several backups, because there will be no queue in this letter if your application does not work, although I am sure that messaging or postfix, etc. can be configured to work with it quite well.

+2
source

Ok This is an alternative solution. Assuming there is no reason why you want to use emails (for example, your information comes from an external source via email), then I would suggest that the database table be a much simpler way to create an input queue.

Simple database polling on a regular basis. This would be much faster than polling an email inbox and much faster than you think. Database polling is very fast, and you can easily test a database table several hundred times per minute with very little impact on performance.

Just create a table to store your Q elements and add an extra field where you can save the timestamp or flag that was processed by this q element, then you just take the next raw element from the stack

e.g. MSSQL

select Top 1 * from tbl_MyQ where AlreadyHandled = 0 

MySQL

 select * from tbl_MyQ where AlreadyHandled = 0 Limit 1 

then

 update tbl_MyQ Set AlreadyHandled = 1 where QueueID = #ItemIDRetrieved# 

Databases are fast, run a test if you are worried. And they are much less complex than IMAP events and email mailboxes.

0
source

If an inbox (IMAP) is a basic requirement in your architecture and there are no IMAP clients available, I would try to find an IMAP client with asynchronous notification written in another language (C, C # or even Java) to implement a "proxy "or the gateway that will then launch your Delphi daemon application when new messages arrive.

The Delphi daemon can use a simple socket protocol or http to receive messages (TIdHTTPServer, TIdTCPClient).

If the Indy learning curve is steep, you can write protoype with the Ararat Synapse TCP / IP library, which is free and open source, it works fine in my Delphi 2009 applications (except that the compiler complains about some string / ansi) .

0
source

Source: https://habr.com/ru/post/1314485/


All Articles