Indy IMAP 客户端的电子邮件到达通知 (Delphi 2009)

发布于 2024-09-08 02:00:47 字数 376 浏览 6 评论 0原文

我正在开发一个使用电子邮件收件箱作为其输入队列的守护程序应用程序。响应时间应尽可能长,服务器开销保持在最低限度,因此轮询电子邮件收件箱是不可能的。由于 IMAP 协议支持新电子邮件通知,因此这对于应用程序来说是理想的选择。

然而,当我尝试在 Delphi/Indy 应用程序中实现此机制时,我遇到了麻烦。 TIdIMAP4 工作得很好(除了一些与我的情况无关的 Unicode 问题),但我找不到在其中实现通知的方法。

这应该是一个简单的 GIYF 问题,但由于一些我未知的原因,我在网上搜索时找不到任何有关 Indy 组件的相关信息。

解决方案或替代方法将不胜感激。

编辑:由于 Indy 显然不支持异步电子邮件通知,有谁知道 delphi 的哪些免费组件可以实现这一点。

I am working on a deamon application that uses e-mail inbox as its input queue. Response times should be as high as possible with server overhead kept to minimum, so polling e-mail inbox is out of question. As IMAP protocol enables the notifications on new e-mails, this is ideal for the application.

However, I've run into troubles when I tried implementing this mechanism in my Delphi/Indy application. TIdIMAP4 works great (apart from some Unicode problems that are irrelevant in my case) but I couldn't find the way to implement notifications in it.

This should be a simple GIYF problem but for some to-me-unknown reason, I cannot find ANY relevant information on Indy components when searching online.

A solution or alternative approaches would be deeply appreciated.

Edit: Since Indy appearently does not support asynchronous e-mail notifications, does anybody know what free components for delphi would enable that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不及他 2024-09-15 02:00:47

TIdIMAP4 不支持接收异步通知,例如新电子邮件通知。这需要将 TIdIMAP4 的实现更改为类似于 TIdTelnet 使用的多线程模型,但由于 TIdIMAP4 当前的阻塞命令/响应模型而更加复杂。目前,您必须定期轮询收件箱。

TIdIMAP4 does not support receiving asynchronous notifications, such as new email notifies. That would require changing TIdIMAP4's implementation to a multithreaded model similar to what TIdTelnet uses, but more complex because of TIdIMAP4's current blocking command/response model. For now, you must poll the inbox periodically.

隔纱相望 2024-09-15 02:00:47

为什么不让应用程序成为 smtp 服务器,而不是客户端。

这样,当电子邮件直接发送到您的应用程序时,您就会收到直接通知,而不是拉取新电子邮件。

有一些后备方案,如果您的应用程序关闭,电子邮件将不会排队,尽管我确信 ms Exchange 或 postfix 等可以设置为很好地使用它。

Why not make the app an smtp server, instead of client.

This way you have direct notification as the email is sent direct to your app, instead of pulling new email.

There are a few fallbacks, in that email won't queue if your app is down, although I'm sure that ms exchange, or postfix etc can be setup to work with it quite well.

﹂绝世的画 2024-09-15 02:00:47

好的。这是一个替代解决方案。假设您没有理由希望使用电子邮件(例如,您的信息是通过电子邮件从外部来源获得的),那么我建议使用数据库表作为创建输入队列的更直接的方法。

只需定期轮询数据库即可。这比轮询电子邮件收件箱要快得多,而且比您想象的要快得多。轮询数据库的速度非常快,您可以轻松地每分钟轮询数据库表数百次,而对性能的影响很小。

只需创建一个表来存储您的 Q 项,并添加一个额外的字段,您可以存储时间戳或该 q 项已被处理的标志,然后您只需从堆栈中取出下一个未处理的项,

例如
mssql

select Top 1 * from tbl_MyQ where AlreadyHandled = 0 

mysql

select  * from tbl_MyQ where AlreadyHandled = 0 Limit 1

然后

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

数据库很快,如果您担心,请运行测试。而且它们比 IMAP 事件和电子邮件收件箱简单得多。

Ok. This is an alternative solution. Assuming there is no reason you wish to use emails (eg your information is coming form an external source via email), then I would suggest a database table to be a much more straightforward way to create an input queue.

Simply poll the database on a regular basis. This would be much, much quicker than polling an email inbox, and much quicker than you think it will be. Polling a database is very fast and you could easily poll a database table several hundred times a minute with very little appreciable affect on performance.

Simply create a table to store your Q items and add an extra field that you can store a timestamp or flag that this q item has been handled, then you just take the next unhandled item off the stack

eg
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 your worried. And they are much much less complicated than IMAP events and email inboxes.

雨后咖啡店 2024-09-15 02:00:47

如果电子邮件收件箱 (IMAP) 是您的体系结构中的基本要求,并且没有可用的 IMAP 客户端,我会尝试找到一个用不同语言(C、C# 甚至 Java)编写的具有异步通知的 IMAP 客户端来实现“当新消息到达时,代理'或网关将触发您的Delphi守护程序应用程序。

Delphi 守护进程可以使用基于套接字的简单协议或 http 来接收消息(TIdHTTPServer、TIdTCPClient)。

如果 Indy 的学习曲线太陡峭,您可以使用 Ararat Synapse TCP/IP 库编写一个原型,该库是免费且开源的,它在我的 Delphi 2009 应用程序中运行得很好(除了编译器抱怨一些字符串/ansi转换)。

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

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

If the learning curve of Indy is to steep, you could write a protoype with the Ararat Synapse TCP/IP library which is free and open source, it works very well in my Delphi 2009 apps (except that the compiler complains about some string/ansi conversions).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文