如何以编程方式捕获电子邮件? (如海报)

发布于 2024-10-09 15:43:57 字数 105 浏览 3 评论 0原文

我需要以编程方式捕获电子邮件以及使用 php 附加到电子邮件的任何文件。另外,运行 cron 作业是继续检查是否有新电子邮件的唯一方法,还是有办法在新电子邮件到达时自动触发一些代码?谢谢任何帮助!

I need to programmatically capture emails as well as any files that are attached to them using php. Also is running a cron job the only way to continue checking if there are any new emails or is there a way to automatically fire some code as a new email arrives? Thanks any help is appreciated!

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

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

发布评论

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

评论(3

祁梦 2024-10-16 15:43:57

对于问题的第二部分:如果您运行自己的邮件服务器并且希望避免轮询来获取新邮件,那么您可以向 /etc/aliases 添加一个条目,让您的 MTA 知道转发到您的 PHP 脚本,如下所示:

uploads: "|/usr/bin/php -q /var/flickr/uploads.php"

此条目将告诉您的 MTA 通过管道传送[电子邮件受保护]uploads.php。从那里,您可以读取 STDIN,解析 MIME 消息,并根据需要对其进行处理

(从 Cal Henderson 的书中窃取 构建可扩展的网站。我强烈推荐第 6 章)

To the second part of your question: If you run your own mail server and want to avoid polling to fetch new messages, then you can add an entry to /etc/aliases that lets your MTA know to forward to your PHP script, like so:

uploads: "|/usr/bin/php -q /var/flickr/uploads.php"

This entry will tell your MTA to pipe any emails for [email protected] to uploads.php. From there, you can read STDIN, parse the MIME message, and processes it as you please

(stolen from Cal Henderson's Book Building Scalable Websites. I highly recommend Chapter 6)

歌入人心 2024-10-16 15:43:57

我有一个应用程序可以做到这一点。

  1. 创建一个名为 InboxDownloader 的守护程序(定期执行程序),它连接到您的收件箱并检查邮件。如果有消息,让该守护进程下载它们并将它们放入文件夹中以供进一步处理。
  2. 创建另一个守护进程 MailProcessor,它会遍历下载的文件并解析它们。我的方法是使用基于正则表达式的签名来确定到达的消息类型。我有一组类,每个类都注册为此类消息的潜在“处理程序”,如果匹配,则执行处理程序“执行逻辑”方法,并将该方法的完整内容传递给它。

I have an application that does exactly that.

  1. Create a daemon (regularly executing program), called InboxDownloader that connects to your inbox and checks for messages. If there are messages, have that daemon just download them and place them into a folder for further processing.
  2. Create another daemon MailProcessor, that goes through the downloaded files and parses them out. The way I go about it is using regular-expression based signatures to determine what kind of message arrived. I have a set of classes that each register as a potential "handler" for this type of a message, and if the match is made, the handlers "execute logic" method is executed, and the full contents of the method are passed to it.
彼岸花似海 2024-10-16 15:43:57

您是否了解过 Postie 如何为 WordPress 提供服务?

另请参阅Fetchmail 工具

Did you look at how Postie does it for WordPress?

See also the Fetchmail tool.

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