sub DN () { 'cn=admin,dc=domain,dc=com' } sub PASSWORD () { 'password' } sub SERVER () { 'localhost' } use Carp; use Net::LDAP; # Create connection to the LDAP server and bind authoratively using # administrator credentials my $ldap = Net::LDAP->new( SERVER ); unless ( defined $ldap ) { croak( 'Cannot create connection to LDAP server -- ', $! ); } $ldap->bind ( 'dn' => DN, 'password' => PASSWORD ); my $result = $ldap->add ( 'cn=domain,ou=v_domains,ou=postfix,ou=system_services,dc=domain,dc=com', 'attr' => [ 'cn' => 'domain', 'objectClass' => 'inetLocalMailRecipient', 'mailLocalAddress' => 'username@domain, domain', 'mailRoutingAddress' => 'alias' ] ); if ( $result->code ) { carp( 'Error in adding LDAP entry -- ', $result->error ); } $ldap->unbind;