Vacation Processing for Exim

—by Joel Rennich, mactroll@afp548.com

17 December 2002

With the holidays coming up, it is only natural to turn to your favorite e-mail server and find a way to tell all of your teeming admirers that you will be away from your machine for a bit and that they’ll just have to get along with out you.

Exim is more than happy to serve in this role and has pretty much all of the features that you need to do this right out of the box.

We’re going to add in a new router and a new transport that will send a response back to the sender with a message of your choice. That sender will then be databased for a period of time so that they are able to send you more mail without having to wade through annoying auto-reply messages. Also with a little bit of training the end users will be able to do this all by themselves.

First off we have to add lines to /usr/exim/configure.

First the router. Add this to the routers section of the configure file.

user_vacation:
     driver = accept
     check_local_user
     # do not reply to errors or lists
     condition = "${if or {{match {$h_precedence:} {(?i)junk|bulk|list}} {eq {$sender_address} {}}} {no} {yes}}"
     no_expn
     require_files = /var/mail/vacation/${local_part}/vacation.msg  
     # do not reply to errors and bounces or lists
     senders = " ! ^.*-request@.*:\
                 ! ^owner-.*@.*:\
                 ! ^postmaster@.*:\
                 ! ^listmaster@.*:\
                 ! ^mailer-daemon@.*\
                 ! ^root@.*"
     transport = vacation_reply
     unseen
     user = ${local_part}
     no_verify

Best to put this in before the localuser router. Note the require files line. This looks for a folder with the name of the user in the appropriate place. In my case it would look for the existence of /var/mail/vacation/mactroll/vacation.msg. If that full path isn’t there, it won’t trip the vacation filter. The vacation.msg file is the response that gets sent back to the original sender. In this configuration we happen to be using /var/mail/vacation. However, you are free to put any path that you want in there. This is where training the endusers comes in. If you set this path up to be a sharepoint, all of your users will be able to change their messages themselves.

The name of the user here is important. If you are using virtual domains, this isn’t the user virtual name. Instead it is their shortname that actually exists in the NetInfo database.

Now for the transport. Again put this in the transports section of your configure file. The order here doesn’t matter.

vacation_reply:
     driver = autoreply
     file = /var/mail/vacation/$local_part/vacation.msg
     file_expand
     from = Autoreply System <$original_local_part@$original_domain>
     log = /var/mail/vacation/$local_part/vacation.log
     once = /var/mail/vacation/$local_part/vacation.db
     once_repeat = 7d
     subject = ${if def:h_Subject: {Re: ${quote:${escape:${length_50:$h_Subject:}}} (autoreply)} {I am on vacation} }
     text = "\
     Dear $h_from\n\n\
     This is an automatic reply.  Feel free to send additional\n\
     mail, as only this one notice will be generated.  The following\n\
     is a prerecorded message, sent for $original_local_part@$original_domain:\n\
     ====================================================\n\n\
     "
     to = "$sender_address"

The important part here is the once_repeat line. This determines how often the senders will get replied to. In this configuration it is every 7 days. Change this to suit your needs.

And you’re done. Give it a whirl and see if it works and then go on vacation.