CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2005
    Posts
    93

    List folders in outlook

    I am writing code to redirect mails from perticular EmailAddress.

    For that i am giving user a form in which all the folders in outlook will be listed.

    I am not getting the code to do this.

    I can do this if i want to list folders from perticular folder like inbox by this :
    Code:
    Set myOlApp = CreateObject("Outlook.Application")
            Set name = myOlApp.GetNamespace("MAPI")
            Set fldFolder = name.Folders("olinbox")
            'For Each prfolder In fldFolder
            
            Set objApp = CreateObject("Outlook.Application")
            Set objNS = objApp.GetNamespace("MAPI")
        
        Call GetFolderInfo(fldFolder)
    GetFolderInfo is listing folders in fldfolder.

    But i want to check for all folders in outlook.(like folders in outbox, inbox....)

    How can i list them?

  2. #2
    Join Date
    Oct 2003
    Location
    Timisoara, Romania
    Posts
    460

    Re: List folders in outlook

    Hi v_gyku,
    It is me again So check out the attached code. It's a very usefull application and all my coleagues thanked me three times for creating this It is saving all attachments from all e-mails in selected directory. It creates a directory structure on the disk exactly like the one in your e-mail account. Also check out the filters
    Tell me you opinion about it
    Attached Files Attached Files
    You liked it? Please show your gratitude and rate it!

    There is no 'patch' for stupidity.

  3. #3
    Join Date
    Aug 2005
    Posts
    93

    Re: List folders in outlook

    Code:
    Private Sub CommandButton1_Click() 
        Dim NS As NameSpace 
        Set NS = Application.GetNamespace("MAPI") 
        listSubFolders NS.Folders(1) 
    End Sub 
    Private Sub listSubFolders(f As MAPIFolder, Optional i As Integer) 
        Dim x As MAPIFolder 
        For Each x In f.Folders 
             ' Optional test for email type folders only
             ' If x.DefaultItemType = olMailItem Then
            listFolders.AddItem x.EntryID 
            listFolders.Column(1, listFolders.ListCount - 1) = String(i, "-") & x.Name 
            If x.Folders.count > 0 Then listSubFolders x, i + 1 
             ' End If
        Next 
    End Sub
    I have this code , but its giving me error on this lin :

    Code:
    listFolders.Column(1, listFolders.ListCount - 1) = String(i, "-") & x.Name
    method or data member not found.

    Thanks!

  4. #4
    Join Date
    May 2005
    Location
    Sterling Heights, MI
    Posts
    74

    Re: List folders in outlook

    Quote Originally Posted by vma
    Hi v_gyku,
    It is me again So check out the attached code. It's a very usefull application and all my coleagues thanked me three times for creating this It is saving all attachments from all e-mails in selected directory. It creates a directory structure on the disk exactly like the one in your e-mail account. Also check out the filters
    Tell me you opinion about it
    Very cool!

  5. #5
    Join Date
    Aug 2005
    Posts
    93

    Re: List folders in outlook

    Hello Everyone !

    I am able to take all folders in a listbox.

    If i select a folder which is not user cretaed then my code works fine.
    But if try to route a message to a user created folder then it fails.
    gives error: The operation failed. Object could not be found.

    Code:
     final1 = txtBrowse1.Text
        Set myNameSpace = myOlApp.GetNamespace("MAPI")
        Set myOlApp = CreateObject("Outlook.Application")
        Set fldFolder1 = myNameSpace.Folders(1) 
        Set myInbox = myNameSpace.Folders(1) 
        If final1 = "" Then
        txtBrowse1.SetFocus
        Else
        Dim eidctr, post As Integer
        eidctr = eid1.Count
        post = 1
        While eidctr > 0
        
        MsgBox (fldFolder1.Folders.Item(eid1.Item(post)))
        
             
             Set myDestFolder = fldFolder1.Folders.Item(eid1.Item(post))
            eidctr = eidctr - 1
            post = post + 1
        Wend
        End If
    I am taking entry id of each folder in eid. iTs a collection.

  6. #6
    Join Date
    Aug 2005
    Posts
    93

    Re: List folders in outlook

    I am listing all folders in outlook.
    User will select any folder from a listbox.
    User will select an email id from another listbox.
    When he clicks on command button all the messages from selected email id will be shifted to selected folder.

    If i am selecting a folder like inbox, outbox,drafts, junk email....(which r not user cretaed.) then my code is working fine.

    But if i select user selected folder it gives me error: The operation failed. Object could not be found.

  7. #7
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: List folders in outlook

    I Know all of these stuff.but not in VB in VC++ i can do.So if you wann idea how to do.i can tell .How to implement it's upto you.So exactly what the question and what is the issue here Please let me know.

  8. #8
    Join Date
    Aug 2005
    Posts
    93

    Re: List folders in outlook

    Can u just tell me the concept or logic?
    Why its not working with user cretaed folder.

    Code:
     Set myInbox = myNameSpace.Folders(1)
    This line is taking private folders.

    So, userc retaed folders are public or somthing of that kind?
    THis is why i am getting error?

  9. #9
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Smile Re: List folders in outlook

    you can do like this
    Code:
     CComQIPtr<MAPIFolder> pFolderAcct1;
     CComQIPtr<Outlook::_MailItem > pMailItem(pDisp);
       CComPtr<IDispatch > pDispatch;
       if(pMailItem)
       {
    	hr = pMailItem->Move(pFolderAcct1,&pDispatch); 
    //pFolderAcct1 Where you want to move your E_Mail
    	if(FAILED(hr)) 
    	 return hr;
       }
    This way uou can Move Your data From One Folder to Another.
    But Still One Confusion is there For Me .What yopur require Ment and What u want
    .if you wann you also can Check In MSDN for Application Object and you will find all the nMethod related with OUtlook or you can check ms09out.tlf File For looking various interfaces Provided by Outlook.
    if Still you have Problem Explain your Question Once Agin .that What's your requirement and What you want.

    Thanx

  10. #10
    Join Date
    Aug 2005
    Posts
    93

    Re: List folders in outlook

    Thanks humptydumpty!

    Actually i dont know abc of vc++.
    I will try somthing in VB and let u know...

    Still, thanks for replying......

  11. #11
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: List folders in outlook

    Quote Originally Posted by v_gyku
    Thanks humptydumpty!

    Actually i dont know abc of vc++.
    I will try somthing in VB and let u know...

    Still, thanks for replying......
    u Welcome .but still Problem Let me know.this Time i will try to explain this in VB

  12. #12
    Join Date
    Aug 2005
    Posts
    93

    Re: List folders in outlook

    Sorry but i found out one thing.

    Its not working if folder is ceated inside anyother folder.So, its not an issue with user created folder.
    If i create a folder in personal folder itself then its ok. But if i create folder inside a inbox or outbox or.... then problem.

    What i have to do to access these folders also.
    I dont want to give names of the folders explicitely.
    Suppose i have selected 2 folders from listbox mesage should be moved to these two folders.

    Code:
     
    Dim outarray() As Variant
    Dim outarrayfolder() As Variant
    Dim arrsizefolder As Integer
    Dim tempfolder As String
    Dim destfld As String
    Dim arrsize As Integer
    Dim abcde As String
    Dim final1 As String
    Dim fldFolder1 As MAPIFolder
    Dim myDestFolder As MAPIFolder
    Dim myNameSpace As Outlook.NameSpace
    Dim myInbox As Outlook.MAPIFolder
    Dim myItem As Outlook.MailItem 'Object
        
        final1 = txtBrowse1.Text ' this is folder selected
        Set myNameSpace = myOlApp.GetNamespace("MAPI")
        Set myOlApp = CreateObject("Outlook.Application")
        Set fldFolder1 = myNameSpace.Folders(1) 'Personal folders
        Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) 'myNameSpace.Folders(1) 'inbox
        Dim objfolder As Outlook.MAPIFolder
        
        If final1 = "" Then
        txtBrowse1.SetFocus
        Else
        Dim eidctr, post As Integer
        eidctr = eid1.Count
        post = 1
        
        While eidctr > 0
             
             MsgBox (fldFolder1.Folders.Item(eid1.Item(post))) 'It should display name of folder selected.
        
            Set myDestFolder = fldFolder1.Folders.Item(eid1.Item(post)) 'sets the destination folder
    
            eidctr = eidctr - 1
            post = post + 1
        Wend
        End If
     
        Set myItems = myInbox.Items
      
       Dim folder As MAPIFolder
       j = myInbox.Items.Count
    
    For Each myItem In myInbox.Items
    
               If myItem.Class = olMail Then
                    If myItem.SenderEmailAddress = final Then 'final contains emailaddress
                       myItem.Move myDestFolder
                    End If
               End If
            
    Next
       
       inp = Mid(inp, InStr(inp, delim) + 1)
       arrsize = arrsize + 1
       
       Wend
    My main problem is how will i set destination folder as folder inside inbox or outbox or...........,at the same time it can be inbox outbox.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured