Author Topic: add mail alias to user on command line  (Read 310 times)

grl

  • Zen Apprentice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
add mail alias to user on command line
« on: August 27, 2022, 10:34:33 pm »
HI!

To import existing mail aliases to existing users on a zentyal 7 server I would love to do that via command line.

I found a script dating back from 2012 - this does not work anymore.

Any hint how to add mail aliases from the command line e.g. via perl script?

thanks
Lukas

grl

  • Zen Apprentice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: add mail alias to user on command line
« Reply #1 on: September 06, 2022, 07:46:55 pm »
In case someone else has the same question - this is a little script I hacked together myself. Use it at your own risk - as it was used just to migrate stuff it comes without much error checking and no guarantee of not breaking a lot of things...

Code: [Select]
#!/usr/bin/perl

use strict;
use warnings;
use EBox;
use EBox::Samba::User;
use EBox::MailAliasLdap;
use EBox::Global;

EBox::init();

my $malias = $ARGV[0];
my $myuser = $ARGV[1];
my $mymail = $ARGV[2];

my $users = EBox::Global->modInstance('users');
my $mailAliasLdap = EBox::MailAliasLdap->new();

my $user = EBox::Samba::User->new(samAccountName => $myuser );

if(($mailAliasLdap->aliasExists($malias)))
{
  print "$malias belongs to @{$mailAliasLdap->accountsByAlias($malias)} \n";
}
else
{
  $mailAliasLdap->addUserAlias($user, $malias, $mymail);
  print "Added alias $malias \n";
}


It expects the desired alias as first argument, the username of the user as second and the email of the user as third argument.

regards
Lukas