How To Set Up A Postfix Autoresponder With Autoresponse

Version 1.0
Author: Falko Timme

Autoresponse is an autoresponder for the Postfix MTA. It allows you to create autoresponder messages for email accounts from the shell and also by emailing the autoresponder text to a certain email address.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

The setup that I describe here works for all my "Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail" setups. I don't guarantee that it will work for other setups.

I'm using such a "Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail" here and have set up the email account [email protected] for which I want to create an autoresponder.

 

2 Installing Autoresponse

We can download and install Autoresponse as follows:

cd /tmp
wget http://www.nefaria.com/scriptz/autoresponse-1.6.2.tar.gz
tar xvfz autoresponse-1.6.2.tar.gz
cd autoresponse

useradd -d /var/spool/autoresponse -s `which nologin` autoresponse
mkdir -p /var/spool/autoresponse/log /var/spool/autoresponse/responses
cp ./autoresponse /usr/local/sbin/
chown -R autoresponse:autoresponse /var/spool/autoresponse
chmod -R 0770 /var/spool/autoresponse

Then we edit /etc/postfix/master.cf:

vi /etc/postfix/master.cf

At the beginning of the file, you should see the line

[...]
smtp      inet  n       -       -       -       -       smtpd
[...]

Modify it so that it looks as follows (the second line must begin with at least one whitespace!):

[...]
smtp      inet  n       -       -       -       -       smtpd
   -o content_filter=autoresponder:dummy
[...]

At the end of the file, append the following two lines (again, the second line must begin with at least one whitespace!):

[...]
autoresponder unix - n n - - pipe
     flags=Fq user=autoresponse argv=/usr/local/sbin/autoresponse -s ${sender} -r ${recipient} -S ${sasl_username} -C ${client_address}

Then run...

postconf -e 'autoresponder_destination_recipient_limit = 1'

... and restart Postfix:

/etc/init.d/postfix restart

If you have users with shell access, and you want these users to be able to create autoresponder messages themselves on the shell, you must add each user account to the autoresponse group, e.g. as follows for the system user falko:

usermod -G autoresponse falko 

However, this is not necessary if you want to create all autoresponder messages as root (or use the email feature to create autoresponder messages - I'll come to that in a moment).

 

3 Using Autoresponse

Run

autoresponse -h

to learn how to use Autoresponse:

server1:~# autoresponse -h

/usr/local/sbin/autoresponse [-r {recipient email} -s {sender email} -S {sasl username} -C {client ip}] 
[-e {email address}] [-d {email address}] [-E {email address}] [-D {email address}] [-h]

        -r, -s, -S, and optionally -C must be used together to 
specify a recipient, sender, sasl username, and client IP of an autoresponse message.
           Normally you configure these in postfix's "master.cf" 
but they can be used from the terminal as well (only for testing purposes!).
           If this is executed from a terminal, you'll need to hit CTRL-D
 when you are finished typing your autoresponse message.

        -e is used to create a new autoresponse or edit an existing one for the specified user.
           If a disabled autoresponse message exists, it will be ignored and a new message will be created.

        -d is used to disable an existing active autoresponse message.

        -E is used to enable an existing autoresponse message. If both a disabled AND and an active autoresponse message exist,
           the active message will be overwritten by the disabled one.

        -D is used to delete an existing autoresponse message, it will not delete disabled autoresponse messages.

        -h prints this help menu

server1:~#

To create an autoresponder message for the account [email protected], we run...

autoresponse -e [email protected]

... and type in the autoresponder text:

I will be out the week of March 2 with very limited access to email.
I will respond as soon as possible.
Thanks!
Falko

(You cannot set the subject using this method; by default, the subject of the autoresponder messages will be Out of Office.)

Now send an email to [email protected] from a different account, and you should get the autoresponder message back.

To disable an existing autoresponder, run

autoresponse -d [email protected]

To enable a deactivated autoresponder, run

autoresponse -E [email protected]

To delete an autoresponder, run

autoresponse -D [email protected]

You can modify the RESPONSE_RATE variable in /usr/local/sbin/autoresponse. It defines the time limit (in seconds) that determines how often an autoresponder message will be sent, per email address. The default value is 86400 (seconds) which means if you send an email to [email protected] and receive an autoresponder message and send a second email to [email protected] within 86400 seconds (one day), you will not receive another autoresponder message.

vi /usr/local/sbin/autoresponse
[...]
declare RESPONSE_RATE="86400"
[...]

 

4 Creating/Deleting Autoresponder Messages By Email

Instead of creating autoresponder messages on the command line, this can also be done by email. If you want to create an autoresponder message for the email address [email protected], send an email from [email protected] to [email protected] (this works only if you've set up SMTP-AUTH on your server). The subject of that email will become the subject of the autoresponder message (that way you can define subjects different from Out of Office), and the email body will become the autoresponder text.

If you create an autoresponder this way, Autoresponse will send you an email back like this one (so that you know if the operation was successful):

 Autoresponse enabled for [email protected]  by SASL authenticated user: [email protected]  from: 192.168.0.200   

If there's already an active autoresponder for that email address, it will be disabled (i.e., there's no active autoresponder at all for that address anymore, and you will receive an email telling you so:

Autoresponse disabled for [email protected] by SASL authenticated user: [email protected] from: 192.168.0.200

).

This means the email feature is a toggle switch - if there's no sautoresponder, it will be created, and if there's an autoresponder, it will be disabled.

 

Share this page:

32 Comment(s)