Exchange Server TechCenter > Exchange Server Forums > Development > Change Forwarding Address of a public folder via Visual Basic
Ask a questionAsk a question
 

Proposed AnswerChange Forwarding Address of a public folder via Visual Basic

  • Wednesday, February 11, 2009 12:21 AMAxel Nastansky Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Friday, February 13, 2009 3:55 AMGlen ScalesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed AnswerHas Code
    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

    Foldertomodify = "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  
     
    cheers
    Glen
    • Proposed As Answer byLaeeq Qazi Tuesday, June 23, 2009 12:02 PM
    •  
  • Monday, February 16, 2009 9:15 AMLaeeq Qazi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi there,

                Can I change PF's primary email address using same AD object?

               regards,
              

    Cyber Friend
  • Tuesday, February 17, 2009 12:59 AMGlen ScalesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes you can modify the email addresses for the public folder itself by modifying the proxyaddresses property.

    Cheers
    Glen
  • Tuesday, June 23, 2009 12:01 PMLaeeq Qazi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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
  • Tuesday, July 07, 2009 6:19 PMehabkandeel Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    how can i set objmailbox.altRecipient = nothing ?
    please help
  • Wednesday, July 08, 2009 2:39 AMGlen ScalesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    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
    •  
  • Wednesday, July 08, 2009 7:49 AMLaeeq Qazi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    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
    •  
  • Friday, November 06, 2009 10:32 PMpalizada Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    It was helpful for me.