July 29, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Building an effective autoresponder

  • September 9, 1999
  • By Jay Link
  • Send Email »
  • More Articles »


sendmail tutorial One question commonly posed on USENET is: "Where can I find a good autoresponder?" These posts might suggest that autoresponse programs are hopelessly complex and above the grasp of the average programmer. Fortunately, this isn't the case at all. Autoresponders can be surprisingly simple. With this in mind, the best solution is often to build your own.

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.


Replacing process with program

How 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:

  1. deliver the message to a user's mailbox,
  2. append the message to a file,
  3. send the message to a list of user addresses, or
  4. hand the message off to a program.

It's the last option that we're concerned with.


Local and alias

By 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:

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:

sales: "|/bin/autoreply" info: "|/bin/autoreply"

Or, an even easier method would be:

sales: info info: "|/bin/autoreply"

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



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel