# setting up vacation autoresponse for virtual mail system

## SimianRage

I have an email server set up as described in the virtual mail guide (postfix, courier IMAP, squirrelmail, mysql, etc.) and would like to set up a vacation autoresponse system that lets virtual users modify their own settings.  I'm not sure that the squirrelmail plugin is adequate because it needs a directory writable by the webserver uid and I'm looking for the easiest setup to maintain (i.e., you create the new user and vacation just works without any additional admin intervention).

My idea is this, so tell me if I'm smoking something on this one:

As suggested in the VIRTUAL readme of postfix, control vacation by adding a a virtual alias for the user that points to an autoresponder, and optionally himself if he wants to keep a copy of the incoming email. Since I'm already using maildrop, the autoresponder would have a pipe in the maildrop config to a custom script that grabs the vacation parameters from a vacation table in the mysql db and sends off the reply. Or maybe a program already exists that could be configured to read vacation parameters from a database? I would also need to write a simple web interface (maybe even a plugin to SM) that lets the user set their vacation parameters: on/off, message, subject, cc. This script would update the db and create/delete the virtual alias to the autoresponder address.

I am assuming (perhaps incorrectly) that the autoresponse script can pick off the original recipient in order to lookup the correct vacation parameters for that user. I would also be concerned that my custom script could be used by spammers to relay if they send mail directly to the autoresponder or to an account currently set to vacation.

Any thoughts on this? Maybe I'm overthinking this and a much easier solution exists?

----------

## puggy

Well, procmail is probably what you want to use to actually do the autoresponding. Then I suppose you are going to need some sort of interface for your users to modify "their" procmail settings which could be stored in the database. I think you would probably have to set up a procmail script which reads from the settings in the database fields we've just added.

If you get this working you should certainly post an article on it and docs, tips and tricks and send a link to the virtual mailhosting authors as this would be a worthy addition.

Puggy

----------

## SimianRage

I am using maildrop instead of procmail because postfix won't let you run pipes for virtual domains, but they do the same thing in your scenario I think (correct me if I'm wrong)

Due to time constraints I went with a slightly different solution. It works, but it still requires manual admin to set up each user. I went ahead and installed the squirrelmail plugin courier_vacation-1.0-1.2. Here are the steps I then used to set this up:

1) I created a new directory /home/vmail/vacation that is writable by the apache account

2) I created a new table in the database called vacation, with fields email and vacationdir

3) I configured the courier_vacation plugin config.php file to use this vacation table by setting the userid field = email and home field = vacationdir

4) I created a maildroprc file in /home/vmail/vacation/vacationrc based on the example from the courier_vacation plugin README as follows:

```

# Define some file paths

BASE_PATH="/home/vmail/vacation/$LOGNAME"

VACATION_TEXT="$BASE_PATH/vacation.txt"

VACATION_SUBJ="$BASE_PATH/vacation_subject.txt"

VACATION_CC="$BASE_PATH/vacation_cc_addresses.txt"

VACATION_KEEP="$BASE_PATH/vacation_keep_messages.txt"

# test for vacation file, if it exists, send autoresponse

`test -f $VACATION_TEXT`

if ($RETURNCODE==0)

{

   # test for vacation message subject, use it if found

   `test -f $VACATION_SUBJ`

   if ($RETURNCODE==0)

   {

      SUBJECT=`cat $VACATION_SUBJ`

      cc "| mailbot -A 'From: $LOGNAME' -A 'Subject: $SUBJECT' -t $VACATION_TEXT /usr/sbin/sendmail -f ''"

   # otherwise, regular "Re:" syntax for subject is automatic

   #

   }

   else

   {

      cc "| mailbot -t $VACATION_TEXT -A 'From: $LOGNAME' /usr/sbin/sendmail -f ''"

   }

   # test for any cc addresses, forward to those addresses if present

   #

   `test -f $VACATION_CC`

   if ($RETURNCODE==0)

   {

      # grab cc addresses

      #

      CCADDRESSES=`cat $VACATION_CC`

      # do we need to keep a copy of messages in this account or not?

      #

      `test -f $VACATION_KEEP`

      if ($RETURNCODE==0)

      {

         cc "! -f \"$FROM\" $CCADDRESSES"

      }

      else

      {

         to "! -f \"$FROM\" $CCADDRESSES"

      }

   }

}

```

5) I added an include line in the main maildrop filter file

```

exception {

    include "/home/vmail/vacation/vacationrc"

}

```

The downside is that in order to make this work for a user you have to do 2 steps - create an entry in the vacation table for that user and create a new dirctory in /home/vmail/vacation for that user. For example to set up vacation for nobody@dev.null you would add to the vacation table:

email=nobody@dev.null

vacationdir=/home/vmail/vacation/nobody@dev.null

I guess this should probably go in doc tips and tricks like puggy suggested, but I would still like to get it set up so these per user steps aren't necessary.  I don't know php, but maybe just modifying the squirrelmail plugin to write to the database instead would work. Then I would still need a custom program to replace mailbot and read vacation parameters from the DB instead of files.

----------

## MikePikeFL

 *SimianRage wrote:*   

> 4) I created a maildroprc file in /home/vmail/vacation/vacationrc based on the example from the courier_vacation plugin README as follows:
> 
> 

 

Thanks for all your suggestions above, I have lots of this working. However, when I enable the vacation message for my account, the script executes and I get the following error (both as a return email and in the log file)- the mail also gets trhough, but it bounces with:

```
Command died with status 2: "maildrop". Command output:

    bash: -c: line 0: unexpected EOF while looking for matching `'' bash: -c:

    line 1: syntax error: unexpected end of file
```

I'm not sure what is failing:

-The vacationrc file?

-The line in /etc/postfix/master.cf?

```
maildrop  unix  -       n       n       -       -       pipe

  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
```

-The line in /etc/postfix/main.cf?

```
#mailbox_command = /usr/bin/maildrop -d ${USER}

mailbox_command = maildrop 
```

Any help with this problem would be VERY MUCH appreciated! Thanks!

PS- I checked out the following resources in addition to the above post:

http://archives.neohapsis.com/archives/postfix/2002-04/0937.html

http://www.postfix.org/MAILDROP_README.html

----------

## MikePikeFL

Well I got it working- had to hack up that MAILDROPRC file. I can post my changes if anyone is interested...

----------

## mocsokmike

 *Quote:*   

> Well I got it working- had to hack up that MAILDROPRC file. I can post my changes if anyone is interested...

 

In fact, I have the same problem as you had. Can you put the modified maildroprc file up here?

Thanks a lot in advance!

----------

## MikePikeFL

At this point I don't remember what I did, but here you go!

/home/vacation/vacationrc:

```
## MAILDROPRC

#

BASE_PATH="/home/vacation/$LOGNAME"

AUTO_PATH="/home/$LOGNAME/vacationdb"

SHELL="/bin/bash"

`touch /tmp/$LOGNAME-vacationrc`

# test for vacation file, if it exists, send autoresponse

#

`test -f $BASE_PATH/vacation.txt`

if ($RETURNCODE==0)

{

   # test for vacation message subject, use it if found

   #

   `test -f $BASE_PATH/vacation_subject.txt`

   if ($RETURNCODE==0)

   {

      SUBJECT=`cat $BASE_PATH/vacation_subject.txt`

      cc "| mailbot -d $AUTO_PATH -t $BASE_PATH/vacation.txt -s '$SUBJECT' -A 'From: $LOGNAME@domain.com' /usr/sbin/sendmail -f $LOGNAME@domain.com $FROM"

   # otherwise, regular "Re:" syntax for subject is automatic

   #

   }

   else

   {

      cc "| mailbot -d $AUTO_PATH -t $BASE_PATH/vacation.txt -A 'From: $LOGNAME@domain.com' /usr/sbin/sendmail -f $LOGNAME@domain.com $FROM"

   }

   # test for any cc addresses, forward to those addresses if present

   #

   `test -f $BASE_PATH/vacation_cc_addresses.txt`

   if ($RETURNCODE==0)

   {

      # grab cc addresses

      #

      CCADDRESSES=`cat $BASE_PATH/vacation_cc_addresses.txt`

      # do we need to keep a copy of messages in this account or not?

      #

      `test -f $BASE_PATH/vacation_keep_messages.txt`

      if ($RETURNCODE==0)

      {

         cc "! -f \"$FROM\" $CCADDRESSES"

      }

      else

      {

         to "! -f \"$FROM\" $CCADDRESSES"

      }

   }
```

----------

## mocsokmike

Thanks for the help!

It seems I need to learn a bit about this before I go on, because this whole thing is not working. The problem is with the very basics, if I put the maildrop lines into /etc/postfix/master.cf, my postfix crashes with an error message that the transport is invalid.

I don't want to go into details now, as I can not experiment on this server, it is operational and I cannot let it become out-of-service for even a moment.

Is there no way to do autoreplies with postfix (I have virtual users in an SQL database), without using additional scripts and/or packages?

----------

