金鱼,PHP自动回复脚本

金鱼,用于youcl的PHP自动应答脚本“具有Postfix,Courier,MySQL和SquirrelMail的虚拟用户和域”设置

版本1.0
作者:Falko Timme

Goldfish是Postfix的一个非常简单的自动回复脚本(用PHP编写)。 它只包含一个可以通过cronjob启动的PHP文件。 它与我们的“虚拟用户和域使用Postfix,Courier,MySQL和SquirrelMail”教程配合使用(不能用于其他设置,特别是不使用MySQL数据库的Postfix设置)。

我不会保证这将为您工作!

1初步说明

我假设你已经有一个工作的“虚拟用户和域与Postfix,Express,MySQL和松鼠邮件”设置,例如:

2安装和使用金鱼

首先我们连接到我们的MySQL 邮件数据库,并创建一个名为autoresponder的附加表:

mysql -u root -p
USE mail;
CREATE TABLE `autoresponder` (
`email` varchar(255) NOT NULL default '',
`descname` varchar(255) default NULL,
`from` date NOT NULL default '0000-00-00',
`to` date NOT NULL default '0000-00-00',
`message` text NOT NULL,
`enabled` tinyint(4) NOT NULL default '0',
`subject` varchar(255) NOT NULL default '',
PRIMARY KEY (`email`),
FULLTEXT KEY `message` (`message`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
quit;

之后,我们将最新的金鱼版本下载到/ tmp ,并将goldfish PHP脚本重命名为autoresponder.php

cd /tmp
wget http://remofritzsche.ch/goldfish/download/current.tar.gz
tar xvfz current.tar.gz
cd goldfish-002p1/
mv goldfish-002-p1.php autoresponder.php

然后我们打开autoresponder.php并调整配置部分。 确保填写正确的数据库详细信息(可以使用现有的mail_admin MySQL用户); 在$ conf ['q_mailbox_path']行中,确保用户将表名替换为view_users

vi autoresponder.php
[...]
    ######################################
    # Configuration                      #
    ######################################
    /* General */
    $conf['cycle'] = 5 * 60;

    /* Logging */
    $conf['log_file_path'] = "/var/log/goldfish";
    $conf['write_log'] = true;

    /* Database information */
    $conf['mysql_host'] = "localhost";
    $conf['mysql_user'] = "mail_admin";
    $conf['mysql_password'] = "mail_admin_password";
    $conf['mysql_database'] = "mail";

    /* Database Queries */

    # This query has to return the path (`path`) of the corresponding
    # maildir-Mailbox with email-address %m
    $conf['q_mailbox_path'] = "SELECT CONCAT('/home/vmail/', SUBSTRING_INDEX(email,'@',-1), '/', SUBSTRING_INDEX(email,'@',1), '/') as `path` FROM users WHERE `email` = '%m'";

    # This query has to return the following fields from the autoresponder table: `from`, `to`, `email`, `message` where `enabled` = 2
    $conf['q_forwardings'] = "SELECT * FROM `autoresponder` WHERE `enabled` = 1";

    # This query has to disable every autoresponder entry which ended in the past
    $conf['q_disable_forwarding'] = "UPDATE `autoresponder` SET `enabled` = 0 WHERE `to` < CURDATE();";

    # This query has to activate every autoresponder entry which starts today
    $conf['q_enable_forwarding'] = "UPDATE `autoresponder` SET `enabled` = 1 WHERE `from` = CURDATE();";

    # This query has to return the message of an autoresponder entry identified by email %m
    $conf['q_messages'] = "SELECT `message` FROM `autoresponder` WHERE `email` = '%m'";

    # This query has to return the subject of the autoresponder entry identified by email %m
    $conf['q_subject'] = "SELECT `subject` FROM `autoresponder` WHERE `email` = '%m'";
[...]

然后我们将autoresponder.php移动到/ usr / local / bin ,使其由用户和组vmail拥有 ,并使其可执行:

mv autoresponder.php /usr/local/bin
chown vmail:vmail /usr/local/bin/autoresponder.php
chmod 755 /usr/local/bin/autoresponder.php

现在我们创建日志文件/ var / log / goldfish并使其由用户和组vmail拥有

touch /var/log/goldfish
chown vmail:vmail /var/log/goldfish

我希望autoresponder.php每五分钟执行一次,因此我创建一个由用户vmail运行的cron作业:

crontab -u vmail -e
*/5 * * * * /usr/local/bin/autoresponder.php

而已! 现在您可以在自动回复表中创建自动回复 ,例如使用phpMyAdmin或命令行,例如:

mysql -u root -p
USE mail;
INSERT INTO `autoresponder` (`email`, `descname`, `from`, `to`, `message`, `enabled`, `subject`) VALUES('sales@example.com', 'sales@example.com Autoresponder', '2009-06-08', '2009-06-12', 'I will be out the week of June 8 with very limited access to email.\r\nI will respond as soon as possible.\r\nThanks!\r\nFalko', 1, 'Out of Office');
quit;

这将为2009年6月8日至2000年6月12日期间有效的电子邮件地址sales@example.com创建一个自动回复。由于自动回复cron作业只能每五分钟执行一次,所以自动回复消息不会立即发送,但是在电子邮件发送到sales@example.com地址后五分钟内。

每当从sales@example.com地址发送自动回复者时,应该在/ var / log / goldfish日志文件中看到这样的内容

2009-06-08 07:00:01 Connection to database established successfully
2009-06-08 07:00:01 Database selected successfully
2009-06-08 07:00:01 Successfully updated database (disabled entries)
2009-06-08 07:00:01 Successfully updated database (enabled entries)
2009-06-08 07:00:01 Successfully fetched maildir directories
2009-06-08 07:00:01 Successfully fetched subject of sales@example.com
2009-06-08 07:00:01 Successfully fetched message of sales@example.com
2009-06-08 07:00:02 --------- End execution ------------

3链接

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏