The 'autoreply' program is preinstalled; therefore, the only steps you need to take
are to
create the text file for your reply,
define the appropriate aliases in /etc/mail/aliases,
then run the mailctl restart command to reload the aliases file.
The following instructions assume we are creating an autoresponder for info@example.com, and that the autoresponder is set up so that replies are sent to info-reply@example.com. Both these addresses will be set up by the following instructions.
An autoresponder consists of two components: a reply message, which is automatically
returned to the original sender, and the autoresponder itself, which triggers the
reply message. Unless the autoresponder is for "information only," the original message
is forwarded to the proper recipient as defined in the email aliases file.
The instructions for creating an autoresponder are presented below in two parts.
Part 1 shows how to create the reply message for the autoresponder, and Part 2 details
how to create the autoresponder itself. Please note that the instructions are written
to prevent "autoreply war," a condition where two autoresponders are stuck in a loop
responding to one another endlessly. Please take care to follow these instructions
closely.
Part 1: Create a reply message
In order to set up your autoresponder, you will need to access your server via Telnet/SSH. Type the following at a command prompt:
> cd /etc/mail/replies
This will get you into the replies directory, where you will create the autoreply message. Create a file in this directory and name it after the autoresponder you wish to make.
For this example, the reply message will be named "info":
> pico info
This will open a blank file in which you can create the message. In the reply message (in this example, the info file), define the following header lines, followed by the body of the message:
From: Tells the recipient where the reply came from.
Reply-To: Tells the recipient's email client where replies to this message should be sent.
Subject: Controls what will appear in the subject area of your autoreply.
IMPORTANT!
To avoid an Autoreply War, make sure that the From and Reply-To lines do not point to the email address that is to be used by the autoresponder (which in this example is info@example.com).
Following the headers, you can type any text you would like to include in the body of your reply message. The finished autoresponder will look something like the following:
==========
From: info-reply@example.com
Reply-To: info-reply@example.com
Subject: Thank you for your interest
Thanks for writing!
We received your email and will respond soon.
==========
When you are finished, type CTRL-X to save and close the editor. You will then need to change the permissions on this file to 777 by using the following command:
> chmod 777 info
In this example we will make aliases not only for "info" but also for "info-reply", and then use the "info-reply" alias for the From and Reply-To lines.
Part 2: Create the aliases for the autoresponder and the autoreply message.
This part of the autoresponder setup process continues where part 1 left off. You will now create aliases for the autoresponder, 'info,' and the reply message, 'info-reply.'
Navigate to the /etc/mail/ directory:
> cd /etc/mail/
Edit the /etc/mail/aliases file:
> pico -w aliases
TIP: The -w flag suppresses word wrapping so that you can type in extra long lines.
This defines the aliases for the autoresponder and the reply address.
If you wish to receive messages that are sent to the autoresponder, you will need to define a destination address. The destination address can be an existing user account, alias, or virtual user table on your own server, or a complete email address on another server.
NOTE: Each alias must be entered on a separate, single line. Due to formatting constraints within this document, some of the sample aliases given below may appear to spill over onto more than one line.
Add the following lines to the bottom of this file:
autoresponder:[destination,]"|/usr/local/bin/autoreply -f reply@example.com -a autoresponder@example.com -m /etc/mail/replies/autoresponder [-k -s]"
reply: [destination]
Note that the alias calls the program /usr/local/bin/autoreply, which allows the following options:
-f The address following the -f option specifies who the mail is from in the From: header of the reply message.
-a This option stands for "Allowed." The email address following the -a option is the only address that the Auto-Responder is allowed to reply for. This flag is included for security purposes, and helps avoid Autoreply War. It must match the full email address of the alias that you're defining, for example, "autoresponder@example.com".
-m The file path following the -m flag is the location of the message file to send as the reply message, which is located in the /etc/mail/replies/ directory.
-k When the -k option is used, the original message will appear in the autoreply message.
-s When used with the -k option, the -s option will strip extra headers from the autoreply message that result from including the original message. The -s option has no effect if used without the -k option.
Example 1: Creating an autoresponder
For the purpose of this example, assume you wish to forward incoming messages to the "user2" email account on your server, "example.com." You would then create the following aliases for the autoresponder (info) and the reply message (info-reply):
info: user2,"|/usr/local/bin/autoreply -f info-reply@example.com -a info@example.com -m /etc/mail/replies/info"
info-reply: user2
Example 2: Creating an "Information Only" autoresponder
If you do not wish to receive the original message and want only to send a reply message, simply leave out the optional destination address in the aliases so that your /etc/mail/aliases file contains the following lines:
info: "|/usr/local/bin/autoreply -f info-reply@dexample.com -m /etc/mail/replies/info -a info@example.com"
info-reply: /dev/null
As shown above, for an information-only autoresponder you do not specify a destination for the autoresponder, and the reply alias sends all replies to /dev/null.
Once you have set up the autoreply, close and save your changes to the /etc/mail/aliases file.
Activate the autoresponder with the mailctl restart command:
> mailctl restart
This will reload the aliases file, and your autoreply will take effect immediately.
NOTE: If you need to deactivate the autoreply, simply edit /etc/mail/aliases and place a pound sign (#) at the beginning of the "info" and "info-reply" aliases. Then, type the mailctl restart command again.