Building an effective autoresponder
First, let's define what an autoresponder is. Simply put, an autoresponder is a program designed to respond automatically to incoming e-mail messages. Its ultimate purpose is to save time and labor - why spend hours sending the same response to multiple persons, when you can have a mindless "robot" do it for you? An autoresponse is instantaneous in most cases; it never makes typos; and it never calls in sick. If your server's up, so is the autoresponder. While I've used Perl and Sendmail in my examples, you are by no means limited to those two choices. I've written autoresponders in Bash and C, and there are a host of other languages that can handle the job. I've chosen Perl because of its speed and simplicity, and Sendmail because of its widespread implementation in the Open Source world. If you're using another e-mail server (qmail, for example) I'm sure you could readily adapt the information contained herein to meet your needs. Let's begin by taking a look at what happens when an e-mail message is received by Sendmail. If the recipient is local, Sendmail can do one of four things: It's the last option that we're concerned with. The aliases file may be opened with any text editor and is comprised of one or more rows, each separated into two columns. The left column is the receiving address side (known as the "local"), and the right column is the intended destination for the e-mail message (known as the "alias"). For example, let's say you wanted all mail addressed to user "bob" routed instead to user "mary." You would then have a line such as this in your aliases file: bob: mary This tells Sendmail that all mail originally addressed to bob should instead be sent to mary. Note that the "local" address (the left column) ends with a colon. The columns are then separated by one or more white spaces, which can be spaces or tabs. This syntax is fine for re-routing mail from user to another. However, we want mail to be sent to a program (our autoresponder). To do this, we'll replace "mary" with the correct syntax for a program: bob: "|/bin/autoreply" Now, when a piece of e-mail is sent to "bob", it's handed off to the /bin/autoreply program. Note the enclosing quotation marks, as well as the "pipe" character before the program. Without these, Sendmail would assume that /bin/autoreply is a file that the e-mail should be appended to. Naturally, we don't want that. You can specify that multiple "locals" (left-side entries) be directed towards the same program, as follows:
Or, an even easier method would be:
Here, "sales" is redirected to "info", which is then dumped into the /bin/autoreply program. All mail originally addressed to "info" goes straight to the program, without any finagling. Important: /etc/aliases just contains raw data. The file that Sendmail actually uses is /etc/aliases.db . To create a new /etc/aliases.db (after editing /etc/aliases), you'll need to run "newaliases". Don't forget to do this. |
Page 1 of 2
This article was originally published on September 9, 1999