autorespond Copyright 1998 Eric Huss 2/13/98 - First release. 2/14/98 - Fixed file descriptor bug (wouldn't work on BSD/Linux) Simple autoresponder for qmail. ============================================== Here is an autoresponder I wrote for qmail. The motivation to write this autoresponder is that it is very difficult to catch loops with an autoresponder if you set the address of the auto-response the same as the address of the autoresponder. Example: Mail is sent to help@my-company.com. An automatically generated response is sent back to the user with an address of "help@my-company.com". You can set the envelope sender to an empty string. However, some programs will parse the message for the "From:" field and send an autoresponse back to it. It is received at your autoresponder, and you now have a mail loop. This autoresponder also catches some other simple situations such as mail from a mailer-daemon, empty envelope sender, bulk precedence headers, etc. Setting up the Autoresponder ============================ There are two different autoresponders included in this package. The first one is autorespond.c. This version uses a simple directory storage technique to log incoming mail. The second one is autorespond_mysql.c. This version uses the popular MySQL database to log incoming mail. May be a bit of overkill, but nice if you don't want to mess with files on busy sites. autorespond.c ============= First thing, if your qmail distribution is not in /var/qmail, then go edit line 39 to point to the correct directory. There shouldn't be anything else to configure. Compile: gcc -Wall -o autorespond autorespond.c Or whatever you wish (cc, optimizations, etc.) Should for the most part compile without warnings. Usage is as follows: autorespond time num message dir time - amount of time to consider a message (in seconds) num - maximum number of messages to allow within time seconds message - the filename of the message to send dir - the directory to hold the log of messages So for example, in your ~alias directory, create a .qmail-help file with the following: |autorespond 10000 5 help_message help_autorespond &your-email-address@company.com This will allow up to five messages within about 3 hours. Create a file in your ~alias directory called help_message. It should say something like this: From: Support Subject: Help Response This is a response to your help request. Below is a copy of the message we received. -------- Make sure that "From:" is the first line of the file. You should probably include the dashes to separate your help message from the user's message. An example is included with this package. Create a directory called help_autorespond in your ~alias directory. This is where the log of messages goes. That should be it. autorespond_mysql.c =================== First thing, if your qmail distribution is not in /var/qmail, then go edit line 39 to point to the correct directory. You can also change the database name, user, and password at the top of the file. Compile: gcc -Wall -L/var/mysql/lib/mysql -I/var/mysql/include/mysql \ -o autorespond autorespond_mysql.c -lmysqlclient -lnsl -lsocket -lm Or whatever you wish (cc, optimizations, etc.) Should for the most part compile without warnings. The -lnsl -lsocket is a Solaris thing. Don't use it if you don't need it. Change the directories to point to your installation of MySQL. You'll probably also want to do: strip autorespond This will get the file size down a little with the MySQL libraries. Usage is as follows: autorespond time num message Same as above, but without the directory parameter. The following is assuming you used the default database names. Create the MySQL database: mysqladmin create autoresponder Create a user called "autoresponder". By default this should have a blank password, though you probably should change that. Create the table: mysql autoresponder CREATE TABLE autoresponder ( e_mail CHAR(127) NOT NULL, time_sent INT UNSIGNED NOT NULL ) That should be it. Notes ===== - If the maximum count has been reached, then the message is not forwarded on to you. If you wish to change this behavior, change _exit(99); on line 455 for mysql, 440 for the normal one to: _exit(0); - The message sent out has a blank envelope sender. Some mail systems reject mail with a blank sender. If you find this a problem, edit the line that calls send_message() at the bottom of the program to contain an envelope address of your choice. My apologies from the messy documentation and code. I normally use company libraries to write most things, so this was rather clumsily written with standard c libraries. If you find a problem or have a suggestion, please e-mail me at: e-huss@netmeridian.com If you wish to clean up the code to compile better on different platforms, please send me the changes.