Koozali.org: home of the SME Server

Possible to create multiple email forwardings for the same account instead of 1?

Offline Michail Pappas

  • *
  • 351
  • +1/-0
I want to have a single account, which forwards to (external email accounts) usr1, usr2, usr3. I know it can be done by creating 3 aliases, fwd1, fwd2, fwd3, with each one forwarding to the corresponding usrX account. Finally, an allusers group, that includes the fwdX accounts.

Any simpler way, like specifying multiple forwards on the same account, possible?

Offline mmccarn

  • *
  • 2,656
  • +10/-0
The Mailsorting contrib might do what you want.

Otherwise, you could customize /etc/e-smith/templates-user/.qmail/70Forward to create the forwardings you want.

You could (if ambitious) create a "new feature request" in the bug tracker for multiple forward support, then work out the changes required to support multiple forwards:
- changes to the web panels
- changes to the functions that authenticate email forward values
- changes to 70Forward to parse the 'ForwardAddress' value in the database to create multiple forward lines in the .qmail file.

The following trick generates a correct ".qmail" file for multiple forwards, but may have problems of some sort somewhere (for example, you may no longer be able to save changes to the user account in server-manager if the customized ForwardAddress fails a data verification function):
1. Create the user in server-manager with forwarding set as desired (enabled/disabled; keep local/don't keep local).  Include one forwarding address.
2. Set multiple forwards in a shell using these commands (this will overwrite the forwarding address entered in server-manager):
Code: [Select]
db accounts setprop username ForwardAddress 'user1@domain1.com
&user2@domain2.com
&user3@domain3.com'
signal-event user-modify username

* replace "username" with the user name you want to customize
* DON't include "&" before the first email address (this is inserted by the default template)
* DO include "&" before all extra email addresses
* Surround all email addresses in single quotes to cause the newlines to be saved to the db variable.

This creates a db entry for 'ForwardAddress' that includes newlines (due to the single quotes in the command), and which expands correctly.

Finally, you could combine some of my suggestions:
1) Create a custom version of 70Forward named "71ExtraForwards"
2) edit the custom version to use a new db value (ExtraForwards instead of ForwardAddress)
3) set the new db value instead of ForwardAddress using the command line as described above, or customize 71ExtraForwards to parse the new db value separated by commas or semi-colons.
« Last Edit: July 19, 2012, 02:21:38 PM by mmccarn »

Offline Michail Pappas

  • *
  • 351
  • +1/-0
OMG, that's definitely an uber-informative response! Thank you!

I definitely prefer clean ways to do it, so most likely I'll play around with a 70forward custom-template. I must say though that I certainly appreciated the multiple line trick, slick! :)

Thanks again for your precious time in responding to my questions. I'm certain that these pieces of information will be useful to another SME user.

Offline mmccarn

  • *
  • 2,656
  • +10/-0
OMG, that's definitely an uber-informative response! Thank you!
...
Thanks again for your precious time...
You're welcome.  Actually, I teach myself new stuff by answering forum posts I don't know how to solve.  So thanks for the interesting problem!

I'll play around with a 70forward custom-template

I did some checking -- after setting ForwardAddress manually as I described, you won't be able to edit the user in server-manager without editing the forwarding address.

If you want to use the existing "ForwardAddress" db variable to hold multiple addresses, you will need to customize the email forward validation routine in:
/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/useraccounts.pm.
(and possibly other routines as well).

Since I don't know perl very well I try to stay away from changes that require modification of the server-manager functions.  Consequently, I recommend creating and using the extra db variable I discussed -- this would allow you to support multiple email forwards while confining your changes to the 70Forward template.

Using /etc/e-smith/templates/etc/rc.d/init.d/masq/91adjustPortForward as an example of a comma-separated db variable, you might get what you want using:
Code: [Select]
mkdir -p /etc/e-smith/templates-user-custom/.qmail/
cd /etc/e-smith/templates-user-custom/.qmail/
echo "{
    # vim: ft=perl:
    return '# Forward not set'
        unless (\$props{EmailForward} =~ /^(forward|both)\$/);

    \$OUT .= '&' . \$props{ForwardAddress} . \"\n\";
    my \$forward_list = \$props{ExtraForwards} || '';
    foreach my \$forward (split( ',', \$forward_list)) {
          \$OUT .= '&' . \$forward . \"\n\";
    }
}
" > 70Forward

Note: the above code is intended to be copy/paste command line code that creates this file:
/etc/e-smith/templates-user-custom/.qmail/70Forward

Containing this code:
Code: [Select]
{
    # vim: ft=perl:
    return '# Forward not set'
        unless ($props{EmailForward} =~ /^(forward|both)$/);

    $OUT .= '&' . $props{ForwardAddress} . "\n";
    my $forward_list = $props{ExtraForwards} || '';
    foreach my $forward (split( ',', $forward_list)) {
          $OUT .= '&' . $forward . "\n";
    }
}

When done:
- set the first/primary forward in server-manager, or via db variable using "ForwardAddress"

- set the second and all subsequent forwards via db variable using the db variable "ExtraForwards", separated by commas, eg:
db accounts setprop <username> ExtraForwards 'user1@domain1.com,user2@domain2.com'

- implement the new forwards using:
signal-event user-modify <username>

- check that it's working using:
less /home/e-smith/files/users/<username>/.qmail

Offline Michail Pappas

  • *
  • 351
  • +1/-0
Awesome, will definitely implement and test this over the next days, thanks again!!!