468,272 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Specify E-mail address for public folder

Hi!

I'm trying to manage public folders using C#. I have found some code that
allows me to mail enable a folder:

foreach( System.Management.ManagementObject instmailbox in queryCollection )
{
instmailbox["IsMailEnabled"] = true;
instmailbox.Put();
}

This works fine. However I can't figure out how to actually specify the mail
address of the public folder. Things would of course be easy if I was able
to retrieve the distinguished name of the folder in AD but the problem is
that if 2 folders have the same name then a large random number is added to
the distinguished name of the folder - so I'm unable to guess what the
distinguishedName of the folder is. Can I somehow look up the Exchange
object in AD?

I hope someone can help because this is driving me crazy...

Morten
Nov 17 '05 #1
3 1849
Once the Proxy object in created in Active Directory (i think its the RUS)
will then stamp the folder with the objectGuid of the Active Directory
object. You can get this information via the ADProxypath property in the WMI
Exchange_PublicFolder class. There are two issues with this though firstly
it doesn't happen instantaneously after you issue the put command and also
the GUID you retrieve via WMI needs to be transposed. You can then use the
GUID to bind to the object in Active Directory eg
http://msdn.microsoft.com/library/de...ty_methods.asp.
eg something like this will work as long as you wait for the ADProxypath to
get updated.

Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_PublicFolder"
cComputerName = "."
cPublicFolderPath = "/foldertomailenable/"

strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIServices = GetObject(strWinMgmts)
Set objPubInstances = objWMIServices.ExecQuery ("Select * From
Exchange_PublicFolder Where Path='" & cPublicFolderPath & "'")
For Each objExchange_PublicFolder in objPubInstances
wscript.echo objExchange_PublicFolder.ADProxyPath
objExchange_PublicFolder.IsMailEnabled = true
objExchange_PublicFolder.Put_()
if not isnull(objExchange_PublicFolder.ADProxyPath) then
set objfolder = getobject("LDAP://<GUID=" &
transposeGuid(objExchange_PublicFolder.ADProxyPath ) & ">")
wscript.echo objfolder.name
end if
Next
Function transposeGuid(guid)
transposeGuid = mid(guid,8,2) & mid(guid,6,2) & mid(guid,4,2) _
& mid(guid,2,2) & mid(guid,13,2) & mid(guid,11,2) _
& mid(guid,18,2) & mid(guid,16,2) & mid(guid,21,4) _
& mid(guid,26,12)
end function

You may however be better of just using CDOEXM and the IMailRecipient
Interface to do this using the folder path.

Cheers
Glen
"Morten" <mo**************@hotmail.com> wrote in message
news:u2**************@TK2MSFTNGP14.phx.gbl...
Hi!

I'm trying to manage public folders using C#. I have found some code that
allows me to mail enable a folder:

foreach( System.Management.ManagementObject instmailbox in
queryCollection )
{
instmailbox["IsMailEnabled"] = true;
instmailbox.Put();
}

This works fine. However I can't figure out how to actually specify the
mail address of the public folder. Things would of course be easy if I was
able to retrieve the distinguished name of the folder in AD but the
problem is that if 2 folders have the same name then a large random number
is added to the distinguished name of the folder - so I'm unable to guess
what the distinguishedName of the folder is. Can I somehow look up the
Exchange object in AD?

I hope someone can help because this is driving me crazy...

Morten

Nov 17 '05 #2
Hi!

Thanks for your reply. It seems to me that I can use the TargetAddress
property instead of the ADProxypath. As far as I can see this proprety
corresponds to the LegacyExchangeDN on the AD object. I am able to get the
distinguishedName property by using a DirectorySearcher (C#) that looks for
objects with a LegacyExchangeDN property matching the TargetAddress. Are
there any problems with this approach?

Morten

"Glen Scales [MVP]" <gs*****@outlookexchange.com> wrote in message
news:uh**************@TK2MSFTNGP15.phx.gbl...
Once the Proxy object in created in Active Directory (i think its the RUS)
will then stamp the folder with the objectGuid of the Active Directory
object. You can get this information via the ADProxypath property in the
WMI Exchange_PublicFolder class. There are two issues with this though
firstly it doesn't happen instantaneously after you issue the put command
and also the GUID you retrieve via WMI needs to be transposed. You can
then use the GUID to bind to the object in Active Directory eg
http://msdn.microsoft.com/library/de...ty_methods.asp.
eg something like this will work as long as you wait for the ADProxypath
to get updated.

Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_PublicFolder"
cComputerName = "."
cPublicFolderPath = "/foldertomailenable/"

strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIServices = GetObject(strWinMgmts)
Set objPubInstances = objWMIServices.ExecQuery ("Select * From
Exchange_PublicFolder Where Path='" & cPublicFolderPath & "'")
For Each objExchange_PublicFolder in objPubInstances
wscript.echo objExchange_PublicFolder.ADProxyPath
objExchange_PublicFolder.IsMailEnabled = true
objExchange_PublicFolder.Put_()
if not isnull(objExchange_PublicFolder.ADProxyPath) then
set objfolder = getobject("LDAP://<GUID=" &
transposeGuid(objExchange_PublicFolder.ADProxyPath ) & ">")
wscript.echo objfolder.name
end if
Next
Function transposeGuid(guid)
transposeGuid = mid(guid,8,2) & mid(guid,6,2) & mid(guid,4,2) _
& mid(guid,2,2) & mid(guid,13,2) & mid(guid,11,2) _
& mid(guid,18,2) & mid(guid,16,2) & mid(guid,21,4) _
& mid(guid,26,12)
end function

You may however be better of just using CDOEXM and the IMailRecipient
Interface to do this using the folder path.

Cheers
Glen
"Morten" <mo**************@hotmail.com> wrote in message
news:u2**************@TK2MSFTNGP14.phx.gbl...
Hi!

I'm trying to manage public folders using C#. I have found some code that
allows me to mail enable a folder:

foreach( System.Management.ManagementObject instmailbox in
queryCollection )
{
instmailbox["IsMailEnabled"] = true;
instmailbox.Put();
}

This works fine. However I can't figure out how to actually specify the
mail address of the public folder. Things would of course be easy if I
was able to retrieve the distinguished name of the folder in AD but the
problem is that if 2 folders have the same name then a large random
number is added to the distinguished name of the folder - so I'm unable
to guess what the distinguishedName of the folder is. Can I somehow look
up the Exchange object in AD?

I hope someone can help because this is driving me crazy...

Morten


Nov 17 '05 #3
I can't see any problems with that method the LegacyExchangeDN should be
unique so it should work fine.

Cheers
Glen

"Morten" <mo**************@hotmail.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
Hi!

Thanks for your reply. It seems to me that I can use the TargetAddress
property instead of the ADProxypath. As far as I can see this proprety
corresponds to the LegacyExchangeDN on the AD object. I am able to get the
distinguishedName property by using a DirectorySearcher (C#) that looks
for objects with a LegacyExchangeDN property matching the TargetAddress.
Are there any problems with this approach?

Morten

"Glen Scales [MVP]" <gs*****@outlookexchange.com> wrote in message
news:uh**************@TK2MSFTNGP15.phx.gbl...
Once the Proxy object in created in Active Directory (i think its the
RUS) will then stamp the folder with the objectGuid of the Active
Directory object. You can get this information via the ADProxypath
property in the WMI Exchange_PublicFolder class. There are two issues
with this though firstly it doesn't happen instantaneously after you
issue the put command and also the GUID you retrieve via WMI needs to be
transposed. You can then use the GUID to bind to the object in Active
Directory eg
http://msdn.microsoft.com/library/de...ty_methods.asp.
eg something like this will work as long as you wait for the ADProxypath
to get updated.

Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_PublicFolder"
cComputerName = "."
cPublicFolderPath = "/foldertomailenable/"

strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIServices = GetObject(strWinMgmts)
Set objPubInstances = objWMIServices.ExecQuery ("Select * From
Exchange_PublicFolder Where Path='" & cPublicFolderPath & "'")
For Each objExchange_PublicFolder in objPubInstances
wscript.echo objExchange_PublicFolder.ADProxyPath
objExchange_PublicFolder.IsMailEnabled = true
objExchange_PublicFolder.Put_()
if not isnull(objExchange_PublicFolder.ADProxyPath) then
set objfolder = getobject("LDAP://<GUID=" &
transposeGuid(objExchange_PublicFolder.ADProxyPath ) & ">")
wscript.echo objfolder.name
end if
Next
Function transposeGuid(guid)
transposeGuid = mid(guid,8,2) & mid(guid,6,2) & mid(guid,4,2) _
& mid(guid,2,2) & mid(guid,13,2) & mid(guid,11,2) _
& mid(guid,18,2) & mid(guid,16,2) & mid(guid,21,4) _
& mid(guid,26,12)
end function

You may however be better of just using CDOEXM and the IMailRecipient
Interface to do this using the folder path.

Cheers
Glen
"Morten" <mo**************@hotmail.com> wrote in message
news:u2**************@TK2MSFTNGP14.phx.gbl...
Hi!

I'm trying to manage public folders using C#. I have found some code
that allows me to mail enable a folder:

foreach( System.Management.ManagementObject instmailbox in
queryCollection )
{
instmailbox["IsMailEnabled"] = true;
instmailbox.Put();
}

This works fine. However I can't figure out how to actually specify the
mail address of the public folder. Things would of course be easy if I
was able to retrieve the distinguished name of the folder in AD but the
problem is that if 2 folders have the same name then a large random
number is added to the distinguished name of the folder - so I'm unable
to guess what the distinguishedName of the folder is. Can I somehow look
up the Exchange object in AD?

I hope someone can help because this is driving me crazy...

Morten



Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by unwiseone | last post: by
3 posts views Thread by =?Utf-8?B?Q0QuU21hbGxleQ==?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.