Win32::Exchange - Exchange 5.5 and Exchange 2000 functions |
Win32::Exchange - Exchange 5.5 and Exchange 2000 functions
$provider = Win32::Exchange::new($info_store_server)) || die $rtn." - error creating new object\n'; --- Exchange 5.5 $mailbox = $provider->CreateMailbox($info_store_server,$mailbox_alias_name); if (!$mailbox) { die "Error creating mailbox\n"; } print "Create successful\n"; $mailbox->SetAttributes(\%Attributes); $mailbox->SetOwner("$domain\\$mailbox_alias_name"); --- Exchange 2000 $mailbox_user = $provider->CreateMailbox($info_store_server, $pdc, $mailbox_alias_name, "domainname.com") || print 'Mailbox create failed\n'; $mailbox_user->Win32::Exchange::SetAttributes(\%Attributes) || print 'Set Attributes failed\n';
This module creates and modifies Exchange 5.5 and 2000 Mailboxes, has growing support for Distribution lists, and some server API queries. (eventually it will do more, but for now, that's it.)
Win32::Exchange uses Win32::OLE exclusively (and technically is just a wrapper for the underlying OLE calls).
new()
class method starts a new instance of an Exchange provider object.
It returns a reference to this object or 0 if the creation fails.
The SERVER_NAME argument must not be prepended with backslashes. The optional VERSION argument can be 5.5 or
6.0.AddDLMembers($info_store_server,$dl_name,\@new_dl_members);#Exchange 5.5
AddDLMembers()
function is only implemented for Exchange 5.5. I'll look at modifying Distribution lists
in Exchange 2000, but I think it's just an AD group with special properties. In any case, it's not implemented for Exchange 2000. Sorry.CreateMailbox($server_name,$mailbox_name,[$org,$ou]);#Exchange 5.5
CreateMailbox($server_name,$dc_name,$mailbox_name,$mail_domain,[$storage_group,$mailbox_store]);#Exchange 2000
CreateMailbox()
function behaves differently depending on
which type of provider it is passed (CDO.Person or ADsNamespaces). As well, the arguments for the Exchange
5.5 and 2000 functions are different.GetLDAPPath($server_name,$org,$ou);#Exchange 5.5
GetMailbox($server_name,$mailbox_name,[$org,$ou]);
GetMailbox()
function is only implemented for Exchange 5.5.
It didn't make sense to have GetMailbox for Exchange 2000, since the underlying object for mailbox creation in
Exchange 2000 is an NT User account, and you have to query the Interface on the User Account ever y time to manipulate Exchange related data, anyway.
GetVersion($server_name,\%version)
LocateMailboxStore($info_store_server,$storage_group,$mailbox_store,$store_name,[\@counts])
SetAttributes(\%attrs);Exchange 5.5
SetAttributes(\%attrs);Exchange 2000
SetAttributes()
method takes a specially formed hash structure,
and is different depending on which version of Exchange you are trying to set attributes for:SetOwner()
method takes a string reference
(ex. "DOMAIN\USERNAME") and is currently only applicable for use in setting the owner on
Exchange 5.5 mailboxes.SetPerms()
method takes an array reference of user or
group names, and is currently only applicable for use in setting permissions on Exchange 5.5 mailboxes.use Win32::Exchange; use Win32::AdminMisc; $domain = Win32::DomainName(); $pdc = Win32::AdminMisc::GetPDC($domain); $mailbox_alias_name='thisisatest'; $mailbox_full_name="This $mailbox_alias_name Isatest"; $info_store_server="HOMEEXCH2"; if (!Win32::Exchange::GetVersion($info_store_server,\%ver) ) { die "$rtn - Error returning into main from GetVersion\n"; } print "version = $ver{ver}\n"; print "build = $ver{build}\n"; print "service pack = $ver{sp}\n"; if (!($provider = Win32::Exchange::new($info_store_server,$ver{'ver'}))) { die "$rtn - Error returning into main from new ($Win32::Exchange::VERSION)\n"; } if ($ver{ver} eq "5.5") { if (!Win32::Exchange::GetLDAPPath($info_store_server,$org,$ou)) { print "Error returning into main from GetLDAPPath\n"; exit 1; } print "GetLDAPPath succeeded\n"; if ($mailbox = $provider->GetMailbox($info_store_server,$mailbox_alias_name,$org,$ou)) { print "Mailbox already existed\n"; if ($mailbox->SetOwner("$domain\\$mailbox_alias_name")) { print "SetOwner in GetMailbox worked!\n"; } } else { $mailbox = $provider->CreateMailbox($info_store_server,$mailbox_alias_name,$org,$ou); if (!$mailbox) { die "error creating mailbox\n"; } print "We created a mailbox!\n"; } $Exchange_Info{'Deliv-Cont-Length'}='6000'; $Exchange_Info{'Submission-Cont-Length'}='6000'; $Exchange_Info{'givenName'}="This"; $Exchange_Info{'sn'}="Isatest"; $Exchange_Info{'cn'}=$mailbox_full_name; $Exchange_Info{'mail'}="$mailbox_alias_name\@insight.com"; $Exchange_Info{'rfc822Mailbox'}="$mailbox_alias_name\@insight.com"; $smtp="smtp:another_name_to_send_to\@$mail_domain"; push (@$Other_MBX,$smtp); #be careful with 'otherMailbox'es.. You are deleting any addresses that may exist already #if you set them via 'otherMailbox' and don't get them first (you are now forewarned). $Exchange_Info{'otherMailbox'}=$Other_MBX; $mailbox->SetAttributes(\%Exchange_Info); $mailbox->SetOwner("$domain\\$mailbox_alias_name"); my @PermsUsers; push (@PermsUsers,"$domain\\$mailbox_alias_name"); push (@PermsUsers,"$domain\\Exchange Perm Users"); #Group that needs perms to the mailbox... $mailbox->SetPerms(\@PermsUsers); my @new_dl_members; push (@new_dl_members,$mailbox_alias_name); $provider->AddDLMembers($info_store_server,"newdltest",\@new_dl_members); } elsif ($ver{ver} eq "6.0") { $storage_group = ""; #you'd need to define this if you had more than 1 storage group on 1 server. $mailbox_store = ""; #you'd need to define this if you had more than 1 mailbox store on 1 or more storage groups. if (Win32::Exchange::LocateMailboxStore($info_store_server,$storage_group,$mailbox_store,$store_name,\@counts)) { print "storage group = $storage_group\n"; print "mailbox store = $mailbox_store\n"; print "located store distinguished name= $store_name\n"; print "$info_store_server\n"; print " Total:\n"; print " storage groups = @counts[0]\n"; print " mailbox stores = @counts[1]\n"; } if ($new_mailbox_user = $provider->CreateMailbox($info_store_server, $pdc, $mailbox_alias_name, "insight.com" ) ) { print "Mailbox create succeeded\n"; } else { die "Failure is the option that you have selected!\n"; } #be careful with proxy addresses.. You are deleting any addresses that may exist already #if you set them via ProxyAddresses (you are now forewarned). push (@$proxies,'SMTP:'.$mailbox_alias_name.'@manross.net'); push (@$proxies,'smtp:secondary@manross.net'); push (@$proxies,'smtp:primary@manross.net'); push (@$proxies,'smtp:tertiary@manross.net'); $Attributes{"IMailRecipient"}{ProxyAddresses} = $proxies; $Attributes{"IMailRecipient"}{IncomingLimit} = 6000; $Attributes{"IMailRecipient"}{OutgoingLimit} = 6000; $Attributes{"IMailboxStore"}{EnableStoreDefaults} = 0; $Attributes{"IMailboxStore"}{StoreQuota} = 100; #at 100KB starts getting warnings $Attributes{"IMailboxStore"}{OverQuotaLimit} = 120; #at 120KB can't send... $Attributes{"IMailboxStore"}{HardLimit} = 130; #at 130KB, can't do anything... if (!$new_mailbox_user->Win32::Exchange::SetAttributes(\%Attributes)) { die "Error setting 2K Attributes\n"; } else { print "Set Attributes correctly\n"; } exit 1; }
This module is based on an Exchange 5.5 Creation script that has been traveling around the Internet and Activestate's mailing list archives for years. I picked up on the thread in 1999, and have been modifying it ever since. With the advent of Exchange 2000, another script came to light, that tried to parse the Storage Group name and Mailbox Store names into an incredibly long string to allow for Exchange 2000 mailbox creation (circa 2001?). I thought that there had to be a better way to do it. As it turns out, there was; LocateMailboxStore is an implementation of that idea.
I'd like to thank the following people:Jan Dubois <jand@activestate.com> and Everyone at Activestate for Win32::OLE, without which this module wouldn't be possible.
Please send questions, comments or suggestions about this module to Steven Manross <steven@manross.net>.
Version 0.0.0.021 August 21, 2002
Win32::Exchange - Microsoft Exchange related functions |