Building an effective autoresponder
Replacing process with programHow does the autoresponder work? Normally, e-mail is delivered to a user's mailbox, but in the case of the autoresponder, it is delivered to a program. The activated program then responds by sending a pre-written message to the original inquirer. Of course, the "canned" message may be updated as often as the programmer desires; this process of updating the response may be an automated cron job in and of itself.
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.
Local and aliasBy default, Sendmail will attempt to deliver e-mail to a user mailbox. To defer an e-mail elsewhere, you'll need to make a line entry into your aliases file (normally /etc/aliases). (Note: You can find everything you ever wanted to know about your aliases file by typing "man aliases".)
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:
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:
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