解析电子邮件附件的脚本
我正在寻找一种方法来监控 Linux mbox 电子邮件帐户,当电子邮件到达时,我想从电子邮件下载附件并保存附件(CSV 文件),以便 PHP 脚本可以使用它。解决这个问题的最佳方法是什么?我已经研究过 PHP 的 IMAP 函数,但这似乎不是最合适的方法,因为可能只需要一个简单的 bash 脚本?
I am looking for a way to monitor a Linux mbox email account, when an email arrives I would like to download an attachment from the email and save the attachment (CSV file) so that it may be used by a PHP script. What would be the best way of going about this? I have looked at PHP's IMAP functions but this does not appear to be the most appropriate method when a simple bash script may be all that is required?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这种情况,我将电子邮件通过管道传输到 PHP 脚本,并让 PHP 脚本解析电子邮件。您可以获得即时结果,而不是等待 cronjob 拉取电子邮件,
现在您已在
$input
中拥有整个电子邮件,并且您可以使用边界提取 base64 编码信息,然后file_put_contents("/ tmp/file.csv",base64_decode($extracted_file_contents))
确保 chmod +x
For this situation I pipe the email to a PHP script and let the PHP script parse the email. You get instant results versus waiting for a cronjob to pull emails down
now you have the entire email in
$input
and you can use the boundries to extract the base64 encoded information and thenfile_put_contents("/tmp/file.csv",base64_decode($extracted_file_contents))
make sure you chmod +x