View Full Version : "Round Robin" forwarder
Nicofr
03-28-2009, 04:30 AM
I've been a user of DirectAdmin for about 2 years, for a small personnal server and am very satisfied of it; especially because of the support you all provide here, in the forum. Thank you very much to all of you for this. I would like to make a "round robin" forwarder, but cannot find anywhere how I could do this. Let me explain.
In the user->email section, we can create a forwarder.
Using this fonctionality :
emails sent to info@domain.com are forwaded to every users of the list
(user1@domain.com, user2@domain.com, etc.)
I would like to create a "round robin" forwarder, working like this :
for emails sent to info@domain.com
the 1st email is forwarded to user1@domain.com
the 2nd email is forwarded to user2@domain.com
etc...
Do you have an idea on how I could do this please?
Best regards,
Nicolas
nobaloney
03-29-2009, 11:13 AM
You'd have to create a script that would do the forwarding and keep track of which forward came before, and then do the next.
Then you'd have to forward email to info@example.com to that script.
Jeff
Nicofr
03-29-2009, 04:06 PM
Thank you for your answer Jeff.
I have to click on "Create new E-Mail Forwarder" in DirectAdmin,
Forwarder name : info
Destination email : "|/home/user/path/to/script.php"
Do you have an example of a script using this DA function please?
I wonder how I can use (forward) the email in my script.
tillo
03-29-2009, 05:19 PM
I had some spare time so I decided to write your script :)
info.pl:
#!/usr/bin/perl -w
use strict;
# TODO
my @recipients = ('first@address.example', 'second@address.example');
# Choose random recipient
my $recipient = $recipients[int rand($#recipients+1)];
# Grab input
my $email = join '',<STDIN>;
# Modify recipient
$email =~ s/^To: .*/To: $recipient/m;
# Send message
open MAIL,"|/usr/sbin/sendmail -t -i";
print MAIL $email;
close MAIL;
Notes: 1) I just love perl, sorry 2) remember to chmod +x info.pl 3) recipients will be chosen at random, if you want a rotation version just ask
Nicofr
03-29-2009, 06:05 PM
:eek: You're totally Awsome! Thank you very much Martino!
1) & 2) ok
3) yes, I'd prefer a rotation version if that's possible please;
4) please send me your email by pm, I'd like to give you a little gift.
tillo
03-29-2009, 08:19 PM
3)
info.pl:
#!/usr/bin/perl -w
use strict;
# Look at the end of this script for help on the file format
my $recipientsFile = "/home/user/info.rcptlist";
# Initialisation
my $recipients = '';
my $recipient = '';
my $first = 1;
# Parse recipients
open RCPTH,$recipientsFile or
die "Can't open recipients file: $!";
while(<RCPTH>) {
chomp;
my $address = $_;
if ($first) {
$recipient = $address;
$first = 0;
} else {
$recipients .= $address."\n";
}
}
close RCPTH;
$recipients .= $recipient."\n";
# Grab input
my $email = join '',<STDIN>;
# Modify recipient
$email =~ s/^To: .*/To: $recipient/m;
# Send message
open MAIL,"|/usr/sbin/sendmail -t -i";
print MAIL $email;
close MAIL;
# Save recipients
open RCPTH,">$recipientsFile";
print RCPTH $recipients;
close RCPTH;
__END__
The recipients file must have this format:
-----------------------
first@address.example
second@address.example
third@address.example
-----------------------
When running this script, the file will be rewritten like this:
-----------------------
second@address.example
third@address.example
first@address.example
-----------------------
And so on, it rotates all addresses.
4) I love gifts :) my Email address is tillo@tillo.ch
Nicofr
03-30-2009, 12:55 AM
Tillo, 2 short words on the paper, far bigger in their signification: Thank You.
I was thinking about the following files organization:
- the script itself (here info.pl)
- recipients: file with emails of recipients
- actual_recipient: a file containing a pointer
Your solution is far smarter: by rotating the recipients_file itself,
no need to keep the pointer updated when adding or removing recipients,
(and no need to count the total recipients number) because the first line
is used as the "actual" recipient.
You very helped me Tillo.
I try this today and keep you informed.
Are you a fine wine amateur?
tillo
03-30-2009, 03:51 AM
I'm glad you like it :) I tested it rapidly on my system, but if you have any problem just copy/paste here (exim sends a delivery error message if there is any error output).
You are too kind, it wasn't a big deal. But yes, I like wine :) Thanks!
Nicofr
03-30-2009, 08:18 AM
You're great
Everything is working very well!
Thank you Tillo
Powered by vBulletin™ Version 4.0.4 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.