简体   繁体   English

通过PHP访问Linux服务器上的邮件队列

[英]PHP access to mail queue on Linux server

I wonder if someone can help with a query I have. 我想知道是否有人可以帮助我进行查询。 My server recently had an email account hacked and subsequently a large amount of spam appear in the mail queue. 我的服务器最近有一个电子邮件帐户被黑客入侵,随后大量垃圾邮件出现在邮件队列中。 I've changed the password on the email account in question and used qmHandle to remove the spam from the mail queue. 我已经更改了相关电子邮件帐户的密码,并使用qmHandle从邮件队列中删除了垃圾邮件。 I would like to prevent this from happening again and I was wondering if it would be possible for PHP to access the mail queue and run a cron job that could run every hour and run a script to alert me if the mail queue exceeds a set amount of mails so I could be alerted and react accordingly? 我想防止这种情况再次发生,我想知道PHP是否有可能访问邮件队列并运行可能每小时运行一次的cron作业,并运行脚本以在邮件队列超过设置的数量时提醒我邮件,以便可以提醒我并做出相应反应? My server is Linux running Redhat if that makes any difference? 我的服务器运行的Linux是Redhat,如果有什么不同吗?

Many thank in advance. 许多人预先表示感谢。

As i don't know which Maildaemon you use, i can just throw some things to think about: 因为我不知道您使用哪个Maildaemon,所以我可以提出一些思考的方法:

  1. To display the que, use "mailq" (on a Debian/Postfix system) 要显示查询,请使用“ mailq”(在Debian / Postfix系统上)
  2. To access it from php, use "sudo" (execute a command as root from non priviledged user) 要从php访问它,请使用“ sudo”(以非特权用户的root用户身份执行命令)
  3. Maybe filter/group it by adding "grep" to "mailq" 也许可以通过在“ mailq”中添加“ grep”来对其进行过滤/分组

Since you are using qmail, and you have qmHandle on the server, it's fairly straight-forward. 由于您正在使用qmail,并且服务器上具有qmHandle,因此非常简单。 qmHandle -s will give you some statistics, including the number of messages in the remote queue. qmHandle -s将为您提供一些统计信息,包括远程队列中的消息数。 The remote queue contains outgoing messages that are queued for delivery. 远程队列包含排队等待传递的传出消息。 You can cobble together a one-liner using grep and cut, which will give you just the count of the number of messages in the remote queue, like so: qmHandle -s | grep remote | cut -d: -f2 您可以使用grep和cut拼凑一线,这将使您仅获得远程队列中消息数的计数,如下所示: qmHandle -s | grep remote | cut -d: -f2 qmHandle -s | grep remote | cut -d: -f2

you don't need PHP to do that. 您不需要PHP就能做到。 A simple bash script ran by cron would do it. 一个简单的由cron运行的bash脚本就可以做到。 Somethig like that: 像这样的东西:

 nbline=`mailq|wc -l` if [ $nbline -gt $seuilMails ] then echo -e "\\nSeuil queue postfix dépassé ($nbline lignes)" >> $msgFile sendmail=true else echo -e "\\nQueue postfix normale" >> $msgFile fi if [ "$sendMail" == true ]; then mailto_admins "$sujet" "$msgFile" fi 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM