如何以编程方式捕获电子邮件? (如海报)
我需要以编程方式捕获电子邮件以及使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于问题的第二部分:如果您运行自己的邮件服务器并且希望避免轮询来获取新邮件,那么您可以向 /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]
touploads.php
. From there, you can readSTDIN
, parse the MIME message, and processes it as you please(stolen from Cal Henderson's Book Building Scalable Websites. I highly recommend Chapter 6)
我有一个应用程序可以做到这一点。
I have an application that does exactly that.
您是否了解过 Postie 如何为 WordPress 提供服务?
另请参阅Fetchmail 工具。
Did you look at how Postie does it for WordPress?
See also the Fetchmail tool.