"Round Robin" forwarder

Nicofr

Verified User
Joined
Mar 28, 2009
Messages
5
How to create a "Round Robin" forwarder

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 [email protected] are forwaded to every users of the list
([email protected], [email protected], etc.)

I would like to create a "round robin" forwarder, working like this :
for emails sent to [email protected]
the 1st email is forwarded to [email protected]
the 2nd email is forwarded to [email protected]
etc...

Do you have an idea on how I could do this please?

Best regards,
Nicolas
 
Last edited:
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 [email protected] to that script.

Jeff
 
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.
 
Last edited:
I had some spare time so I decided to write your script :)

info.pl:
Code:
#!/usr/bin/perl -w
use strict;

# TODO
my @recipients = ('[email protected]', '[email protected]');

# 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
 
: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.
 
Last edited:
3)
info.pl:
Code:
#!/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:

-----------------------
[email protected]
[email protected]
[email protected]
-----------------------

When running this script, the file will be rewritten like this:

-----------------------
[email protected]
[email protected]
[email protected]
-----------------------

And so on, it rotates all addresses.

4) I love gifts :) my Email address is [email protected]
 
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?
 
Last edited:
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!
 
Back
Top