Postfix & Virtual Users Auto Responder

Wess Bechard mailscanner at ELIQUID.COM
Fri Jan 14 20:26:17 GMT 2005


    [ The following text is in the "utf-8" character set. ]
    [ Your display is set for the "US-ASCII" character set.  ]
    [ Some characters may be displayed incorrectly. ]

Hello Folks.

I have managed to get a working auto response system working for
MailScanner users running Postfix with MySQL based virtual users. 

I may be slightly off topic with this post, but auto responders are
difficult to come by for this virtual setup.  Julian,  I hope you don't
mind me posting here to help our Postfix users. :)

Here we go, with some formatting to make this readable.

________________________________________________________________________

--- Description ---
I pieced together a system of old fixes, modified code, and put together
a semi-simple way to use auto responders with MailScanner, Postfix, and
Virtual Users.  You will need to make a few database entrees and create a
text file to use this system.

--- Instructions ---
1.  This perl script can be run from anywhere, but I chose to place it in
my virtual mail directory. (/home/vmail/)  I have set the ownership to my
vmail user.

--- autoreply code start ----

#!/usr/bin/perl -w
#
# Filename: autoreply
# Updated By: Wess Bechard <wess at eliquid.com>
# Author: David Miller <dmillernewportnet.com>, based on a
# script posted to the postfix-users maillist by
# Gimbert Mario <mgimbertsbsd.de> on 02 Dec 2002.
#
#
use strict;
package main;
# location of sendmail binary
my $SENDMAIL = "/usr/sbin/sendmail";

#----------------------------
# Main Thread of Execution
#----------------------------
#my ($sender, $reciplist) = $ARGV;
my ($sender, $reciplist) = @ARGV;
# do not reply to mailing lists
exit 0 if($sender=~/^(?i)owner-.*|^(?i)newsletter.*|(?i)listserver.*|^(?i)mailerdaemon.*
^(?i)mailer-daemon.*/);

# break apart recipient list
$reciplist=~s/,/ /g;
#print "$reciplist\n";
my @recips = split(" ", $reciplist);

# check each recipient and send mail
foreach my $rec (@recips) {
         my ($user, $domain) = split("@", $rec);
         $domain =~ s/autoreply\.//;
         my $file = "/home/vmail/$domain/$user/autoreply.txt";
#        print "$file\n";
         if( -f $file) {
        #        print "$file\n";
                 sendreplyto($sender, "$user\@$domain", $file);
         }
}

exit 0;

sub sendreplyto
{
         my ($sender, $recip, $replyfile);
         ($sender, $recip, $replyfile) = @_;
         #print "$replyfile";
         open(MAIL, "|$SENDMAIL -f '' -t") ||
                 die "Cannot execute $SENDMAIL: $!\n";
         print MAIL <<EOF;
From: $recip (Automatic reply service)
To: $sender
Subject: $recip is away from the mail
EOF
         # send contents of reply file
         open(REPLY, "<$replyfile") ||
                 die "Cannot open file $replyfile $!\n";
         while(<REPLY>) {
                 print MAIL $_;
         }
         print MAIL "\n";
         close REPLY || die "Close of $replyfile failed: $!\n";
         close MAIL || die "$SENDMAIL failed: $!\n";
}

--- autoreply code end ----


2.  Add the following transport to the end of your
/etc/postfix/master.cf.

autoreply unix  -       n       n       -       -       pipe
  flags=F user=vmail argv=/home/vmail/autoreply $sender $recipient

Please change the user to match the permissions set to the perl script.


3.  Please add the following data to the transport table if it does not
exist.
This step will need to be done once for every domain using auto
responders.

In Transport table:
Domain:  autoreply.domain.tld
Destination:  autoreply

4.  Create a forward for the user that uses the new autoreply transport.

In Virtual table:
Create a forward to the user's usual inbox first.
Email: user at domain.tld
Destination: user at domain.tld

Now create a forward to the autoreply.
Email: user at domain.tld
Destination: user at autoreply.domain.tld

5.  Create the autoreply.txt in the user's maildir.

/home/vmail/domain.tld/user/autoreply.txt

Adjust directory path to taste.
The autoreply.txt can contain any plain text email message.


-------------------------------------------------------------------------------
-----------

I hope this help out a lot of people.  Feel free to visit me on the
MailScanner IRC chat room if you need any assistance.

MailScanner on IRC
Community Support
irc.freenode.net
#mailscanner

--

 Wess Bechard
Systems Administrator
eliquidMEDIA
International Inc.

wess at eliquid.com
519.973.1930 -1.800.561.7525

Wess Bechard
System Administrator
eliquidMEDIA International
www.eliquid.com

MailScanner on IRC
Community Support
irc.freenode.net
#mailscanner ------------------------ MailScanner list
------------------------
To unsubscribe, email jiscmail at jiscmail.ac.uk with the words:
'leave mailscanner' in the body of the email.
Before posting, read the MAQ (http://www.mailscanner.biz/maq/)
and the archives (http://www.jiscmail.ac.uk/lists/mailscanner.html).

Support MailScanner development - buy the book off the website!



More information about the MailScanner mailing list