How To Set Up A Postfix Autoresponder With Autoresponse

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2009-04-02 10:34. :: Postfix

How To Set Up A Postfix Autoresponder With Autoresponse

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 03/25/2009

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 falko@example.com 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 falko@example.com, we run...

autoresponse -e falko@example.com

... 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 falko@example.com from a different account, and you should get the autoresponder message back.

To disable an existing autoresponder, run

autoresponse -d falko@example.com

To enable a deactivated autoresponder, run

autoresponse -E falko@example.com

To delete an autoresponder, run

autoresponse -D falko@example.com

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 falko@example.com and receive an autoresponder message and send a second email to falko@example.com 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 falko@example.com, send an email from falko@example.com to falko+autoresponse@example.com (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 falko@example.com by SASL authenticated user: falko@example.com 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 falko@example.com by SASL authenticated user: falko@example.com 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.

 

5 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Luca (not registered) on Tue, 2014-08-12 12:24.
Hi,
I followed the tutorial and everything works except the abilitation of autoresponse email. 
when i sending the email EX: "sistemi+autoresponse@metreta.com", the mail is delivered and see it .. but I do not see any email autoresponse. from shell it works perfectly. 

Best Regards,
Luca
Submitted by nibble (not registered) on Tue, 2014-08-12 12:12.
Hi,
 
I followed the tutorial and everything works except the abilitation of autoresponse email.  
when i sending the email EX: "sistemi+autoresponse@metreta.com", the mail is delivered and see it .. but I do not see any email autoresponse. from shell it works perfectly. 
 
Best Regards,
Luca 

Submitted by Remsztorm (not registered) on Fri, 2013-04-12 12:55.

Great work, thanks. I spend lot of time to find this.

 

 

Submitted by Rias A. (not registered) on Sun, 2011-11-27 00:57.

Use vi to change line #156 of the script (/usr/local/sbin/autoresponse) to the following line, if you want to replace all occurrences of SENDEREMAIL in the autoresponse text with the sender's e-mail address (variable SENDER):

(cat "${RESPONSES_DIR}/${RECIPIENT}") | sed -e "0,/^$/ { s/^To:.*/To: <${SENDER}>/ }" -e '0,/^$/ { /^Date:/ d }' | ${SENDMAIL} -i -f "${RECIPIENT}" "${SENDER}"

... becomes:

(cat "${RESPONSES_DIR}/${RECIPIENT}") | sed -e "0,/^$/ { s/^To:.*/To: <${SENDER}>/ }" -e "{ s/SENDEREMAIL/${SENDER}/ }" -e '0,/^$/ { /^Date:/ d }' | ${SENDMAIL} -i -f "${RECIPIENT}" "${SENDER}"
( I deliberately used the keyword SENDEREMAIL and not SENDER in case the keyword SENDER comes up inside the text in a different context.)

This change becomes in handy if you want the autoresponse text to contain unsubscribe links etc.. So your autoresponse text could look something like this:

Thank you... blah blah... unsubscribe here: http://www.mydomain.com/unsub.php?id=SENDEREMAIL

And it will be becomes this when it gets sent out:

Thank you... blah blah... unsubscribe here: http://www.mydomain.com/unsub.php?id=thename@thedomain.com

I couldn't figure out how to contact Charles from nefaria.com to ask him if he wants to include this in the next version. If you find him, please ping him :-)

Submitted by dynaguy (registered user) on Fri, 2010-08-27 00:54.
 When I test using emailsetup autoresponse,  the maillog shows:
 
Aug 26 16:20:31 gamma postfix/smtpd[5491]: NOQUEUE: reject: RCPT from gamma.sjgeophysics.com[127.0.0.1]: 550 5.1.1 <dynaguy+autoresponse@mydomain.com>: Recipient address rejected: User unknown in virtual mailbox table; from=<dynaguy@mydomain.com> to=<dynaguy+autoresponse@mydomain.com> proto=ESMTP helo=<192.168.123.42>
 
My mail server use SMTP_AUTH. If I send a normail email, log shows:
 Aug 26 16:18:33 gamma postfix/smtpd[5249]: connect from gamma.mydomain.com[127.0.0.1]
Aug 26 16:18:33 gamma postfix/smtpd[5249]: 252102D70081: client=gamma.mydomain.com[127.0.0.1], sasl_method=LOGIN, sasl_username=dynaguy@mydomain.com
Aug 26 16:18:33 gamma postfix/cleanup[5273]: 252102D70081: hold: header Received: from 192.168.123.42 (gamma.mydomain.com [127.0.0.1])??by gamma.mydomain.com (Postfix) with ESMTP id 252102D70081??for <dynaguy@mydomain.com>; Thu, 26 Aug 2010 16:18:33 -0700 (PD from gamma.mydomain.com[127.0.0.1]; from=<dynaguy@mydomain.com> to=<dynaguy@mydomain.com> proto=ESMTP helo=<192.168.123.42>
Aug 26 16:18:33 gamma postfix/cleanup[5273]: 252102D70081: message-id=<10897cbf528c558b6b566ad46e6586b2@gamma.mydomain.com>
Aug 26 16:18:33 gamma postfix/smtpd[5249]: disconnect from gamma.mydomain.com[127.0.0.1]
 
 Any help? 
 
Submitted by Anonymous (not registered) on Tue, 2012-08-14 08:45.

Don't know if it's still important but I searched for an autoreply extensions and found this script very nice. Unfortunately I received the same error "550 unknown recipient..." and went through all parameters in main.cf and finally I found the solution: address extensions must be enabled for this feature to work!

Just uncomment the entry "recipient_delimiter = +" in the file main.cf (in my main.cf I found it on line 426) and restart postfix and then the email-interface for autoresponse is working fine.

Hope this helps all those who are still searching for a solution...

Submitted by MDH (not registered) on Sun, 2010-06-20 13:15.

Hi, one little issue.

The autoreposnder replies to the FROM address of the orignal sender. This is an issue when there is some aliasing going on (ie he REPLY TO address differs to the FROM address).

Do you know how I could force the autoresponder to always use the REPLY-TO address?

Thanks in advance

 

Submitted by MDH (not registered) on Sun, 2010-06-20 11:28.

I installed iRedMail (centos+postfix-dovecot) server then added autoreponse as per your instructions, and within 20 minutes from starting the whole process, I had a fully functional Enterprise ready email sever with autoreponse configured at the sametime as mailbox creation.

awesome job thanks!

Submitted by PJ (not registered) on Thu, 2010-05-13 15:29.
I set this up, and it works great.  However, I need to integrate Amavis and SpamAssassin according to these instructions, flurdy.com/docs/postfix/, but I can't get them all to work together.  How can I accomplish this?  Thanks
Submitted by Anonymous (not registered) on Sat, 2010-06-26 00:03.

you could try iRedMail (google it)

it installs postfix, dovecot, anti virus, anti spam, etc etc the lot.

all well documented, worked great for me...

Submitted by catalin bargaoanu (not registered) on Thu, 2010-05-13 14:35.

works like a charm... good job...

BR

Submitted by JQ (not registered) on Fri, 2009-09-18 09:05.
I am using local user and virtual users. autoresponse seems to work - I got an email response. But, the response email is empty. No subject, no content. I have created enable a response file for user actually. What is wrong?
Submitted by JustinHoMi (not registered) on Mon, 2010-03-29 22:23.
I'm having the same problem. The autoresponses are blank. Did you ever figure this out?
Submitted by Jun (not registered) on Thu, 2009-06-18 23:18.

 

Jun 18 15:14:19 x postfix/smtpd[15108]: NOQUEUE: reject: RCPT from x: 550 5.1.1 <junc+autoresponse@220mm.com>: Recipient address rejected: User unknown in virtual mailbox table; from=<junc@220mm.com> to=<junc+autoresponse@220mm.com> proto=ESMTP helo=<220mmjpchang>

 

Here is error from our log...

 

Thanks

Submitted by pebkac (registered user) on Fri, 2009-04-03 19:13.

will this work with the "Perfect Ubuntu Server 8.10"

--Steve

Submitted by Brendan Lally (not registered) on Sat, 2009-07-18 21:42.
Does NOT work with non virtual user mail accounts.