Change Forwarding Address of a public folder via Visual Basic
- Hello,how do I change the Forwarding Address of a Public Folder programmatically?I have looked at the API references for Exchange but I can't find an appropriate property in CDO, CDOEX or WMI nor have I found anything useful on the web.Could somebody point me to an example on how to do this with Visual Basic? Is there another API I should be looking at?Thank you,Axel
All Replies
- If the folder is already Mail-enabled and forwarding is already set then the easiest method would be to use straight ADSI the property you need to change is the altrecpient property on the AD proxy object for the public folder. You need to set this to the value of the DN of the Ad object your forwarding to. You can use ADSI to look up these value to make it easy eg
cheersFoldertomodify = "pfolder@domain.com" addresstoforwardto = "target@domain.com" set objmailbox = getobject("LDAP://" & getPFdn(Foldertomodify)) wscript.echo "Forwarding Recipient currently set to : " & objmailbox.altRecipient objmailbox.altRecipient = getuserdn(addresstoforwardto) wscript.echo "Forwarding Recipient changed to : " & objmailbox.altRecipient objmailbox.setinfo function getPFdn(emailaddress) set conn = createobject("ADODB.Connection") set com = createobject("ADODB.Command") Set iAdRootDSE = GetObject("LDAP://RootDSE") strNameingContext = iAdRootDSE.Get("defaultNamingContext") Conn.Provider = "ADsDSOObject" Conn.Open "ADs Provider" mbQuery = "<LDAP://" & strNameingContext & ">;(&(objectclass=publicFolder)(mail=" & emailaddress & "));name,distinguishedName;subtree" Com.ActiveConnection = Conn Com.CommandText = mbQuery Set Rs = Com.Execute While Not Rs.EOF pfdn = rs.fields("distinguishedName") rs.movenext wend getPFdn = pfdn end function function getuserdn(emailaddress) set conn = createobject("ADODB.Connection") set com = createobject("ADODB.Command") Set iAdRootDSE = GetObject("LDAP://RootDSE") strNameingContext = iAdRootDSE.Get("defaultNamingContext") Conn.Provider = "ADsDSOObject" Conn.Open "ADs Provider" mbQuery = "<LDAP://" & strNameingContext & ">;(&(objectclass=user)(mail=" & emailaddress & "));name,distinguishedName;subtree" Com.ActiveConnection = Conn Com.CommandText = mbQuery Set Rs = Com.Execute While Not Rs.EOF Userdn = rs.fields("distinguishedName") rs.movenext wend getuserdn = userdn end function
Glen- Proposed As Answer byLaeeq Qazi Tuesday, June 23, 2009 12:02 PM
- Hi there,Can I change PF's primary email address using same AD object?regards,
Cyber Friend - Yes you can modify the email addresses for the public folder itself by modifying the proxyaddresses property.
Cheers
Glen Hi there,
I was having problem in changing PrimarySmtpAddress of a Public folder after mail-enabling it using Set-MailPublicFolder cmd while i was executing that code through .Net Remoting service.
I was always having the error:
The Active Directory proxy object for the public folder '\SalesPF' is being generated. Please try again later.
Now I changed this implementation and instead of calling Set-MailPublicFolder I am now directly manipulating the Publoic Folder Object in AD and changing its primary smtp address using AD attribute 'proxyAddresses'. [ Before it I did disable EmailAddressPolicyEnabled by calling Set-MailPublicFolder]
In addition to this code I also added two security groups to the user under which Remoting Service was running i.e. Exchange Organization Administrators Group and Public Folder Administrator Group. Now all is running fine. Thanx for the nice info on this thread.
Regards,
Laeeq Qazi Snr Software Engineer(Exchange+Sharepoint+BES+DynamicsCRM) www.hostingcontroller.com- how can i set objmailbox.altRecipient = nothing ?
please help - You should be able to use Putex with either 4 delete or 0 clear
eg
objmailbox.PutEx(1,’altRecipient’,0)
Cheers
Glen- Proposed As Answer bypalizada Friday, November 06, 2009 10:30 PM
- You can also do that using .Net DirectoryEntry class, where you will have to use .Clear() method to clear any property I guess.
Regards,
Laeeq Qazi|Snr Software Engineer(Exchange + Sharepoint + BES + DynamicsCRM) www.hostingcontroller.com- Proposed As Answer byLaeeq Qazi Friday, July 10, 2009 7:47 AM
- It was helpful for me.


