寻求(PHP)代码以获取电子邮件,对其进行解析并对其执行操作 [英] Seeking (PHP) code to fetch e-mail, parse it and act upon it

查看:96
本文介绍了寻求(PHP)代码以获取电子邮件,对其进行解析并对其执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我可能重新发明轮子之前,谁能告诉我是否有一个FOSS代码库来定期检查电子邮件(或由cron作业驱动),解析标题和正文并执行某些功能(主要是发送其他电子邮件).

我一直在考虑PHP,因为它是服务器端的,并且擅长字符串处理,但是我对C或C ++会很满意.

嗯,我为什么还要考虑服务器端?我想它可以在我的PC上(添加Delphi,C ++ Builder甚至C#甚至VB)运行(抱歉,没有冒犯的意图;我知道它非常适合于字符串处理,但是我不愿意)不了解PERL,也没有集会的时间来学习.)


我想到了一些通用的代码,这些代码允许定义触发器"并注册回调函数.因此,触发器可能会说sender = XXX,标题包含,收件人地址是等等(或其组合),并且我可以注册一个回调函数,该代码我编写,该回调函数将在满足条件时进行适当的处​​理. /p>


在SourceForge上找到"ETODB是免费的PHP类,它允许解析和提取电子邮件中的数据以与其他php应用程序集成.您可以自动解析电子邮件并将电子邮件转换为数据库记录,将附件保存到特定文件夹,浏览日志." http://sourceforge.net/projects/etodb/

解决方案

imap库是PHP的标准配置-围绕它滚动自己的代码很简单.

但是,轮询电子邮件是解决问题的一种非常无效的方法-更好的方法是将电子邮件(或其副本)直接路由到您的脚本-但是您没有说运行的操作系统是什么也不是您使用的是哪个MTA.假定所有组件都位于运行sendmail或类似文件的Unix机器上,大多数本地传递代理都允许〜/.forward引用脚本.我个人更喜欢procmail(实际上是一种用于传递邮件,制作副本,自动回复等的编程语言.)

Before I probably reinvent the wheel, can anyone tell me if there exists a FOSS code library to check email on a regular basis (or driven by a cron job), to parse the title and body and to perform certain functions (mainly sending other emails).

I was thinking PHP as it is server side and good at string handling, but I would be happy enough with C or C++.

Hmmm, why am I even thinking server side? I suppose that it could just as well run on my PC (add Delphi, C++ Builder and maybe C# or even VB) as possibilities (sorry & no offence intended; I know that it is well suited for string processing, but I don't know PERL and don't rally have time to learn).


Edit: I'm think of some common code which allows to define "triggers" and register callback functions. So, a trigger might say that sender = XXX, title contains, To address is, etc (or combinations thereof) and I can register a callback function which I code which will do the appropriate processing when the condition(s) is met.


Edit: found on SourceForge "ETODB is a free PHP class which allows to parse and extract data from emails to integrate with other php applications. You can automatically parse email messages and convert email to database records, save attachments to specific folders, browse log." http://sourceforge.net/projects/etodb/

解决方案

The imap lib comes as standard with PHP - rolling your own code around this is trivial.

However polling the email is a very inneficient way to solve the problem - a far better approach is to route the email (or a copy thereof) direct to your script - but you don't say what Operating system you are running on nor which MTA your are using. Assuming it all sits on a Unix box running sendmail or similar, most local delivery agents allow ~/.forward to reference a script. My personal preference is for procmail (which is efectively a programming language for delivery mail, making copies, auto-responses etc).

这篇关于寻求(PHP)代码以获取电子邮件,对其进行解析并对其执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆