none
How to calculate the email statistics of 'on behalf of' (outbound) in a mailbox using vbscript? RRS feed

  • Question

  • Hello, I'm having a problem here. Currently I need to calculate number of emails based on 'on behalf of'. There's multiple mailbox and the user have to choose which mailbox he/she wants to calculate. I do not know how to identify or recognized which mailbox did the user select. Is there anyway that I can know which mailbox does the user select? Please help or reply ASAP as I need it urgently!

    The codings that I've tried:

    Dim olApp As Outlook.Application

    Dim olNs As Outlook.NameSpace

    Dim sender As Outlook.AddressEntries

    Dim olParentFolder, olFolderA As Outlook.MAPIFolder

    Dim olMAPI As Object

    Dim mymailbox As Object

    Set olApp = CreateObject ("Outlook.Application")

    Set olNs = olApp.GetNamespace("MAPI")

    set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")

    Set olParentFolder = olNs.PickFolder

    mymailbox = Application.GetNamespace("MAPI").GetDefaultFolder().Parent.Name

    outbound_counter = 0

    sender_name1 = sender_name.Value

    For Each olFolderA In olParentFolder.Folders

    Set email_Item = olFolderA.Items

    For Each email_Item In olFolderA.Items

    If email_Item.Class = olMail Then

    sender_name2 = email_Item.SenderName

    mymailbox = Application.GetNamespace("MAPI").GetDefaultFolder(olParentFolder).Parent.Name

    If mymailbox = sender_name2 Then

    outbound_counter = outbound_counter + 1

    End If

    End If

    I tried the olParentFolder for the GetDefaultFolder but it says type mismatch. :((

    Wednesday, June 6, 2012 10:18 AM

Answers

  • no, selected mailbox will be in folder.Store property that is returned from PickFolder function. In your example it will be like this:

    Dim mymailbox As Store

    Set olApp = CreateObject ("Outlook.Application")

    Set olNs = olApp.GetNamespace("MAPI")

    set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")

    Set olParentFolder = olNs.PickFolder

    Set mymailbox = olParentFolder.Store

    Thursday, June 7, 2012 5:08 AM

All replies

  • you want the user to choose one of mailboxes he has configured in his profile? There is no such exisitng UI to reuse, create your own window with tree or combo to display. You could however invoke PickFolder on Session object and then traverse from selected folder up to Store which would mean mailbox.
    Wednesday, June 6, 2012 10:47 AM
  • I created my own form & did used PickFolder to let the user select. That's why I store the PickFolder into the olParentFolder. Is this the correct way?
    Wednesday, June 6, 2012 4:42 PM
  • no, what is returned from PIckFolder is a Folder object. Use Folder.Store property to determine which mailbox you should use.

    Wednesday, June 6, 2012 6:23 PM
  • So I store the PickFolder into a Folder.Store property? How do I initiate a Folder.Store property? Is it object.ParentFolder?

    I need to find out which mailbox did the user select as there's multiple mailbox for the user to select.

    Thursday, June 7, 2012 1:09 AM
  • no, selected mailbox will be in folder.Store property that is returned from PickFolder function. In your example it will be like this:

    Dim mymailbox As Store

    Set olApp = CreateObject ("Outlook.Application")

    Set olNs = olApp.GetNamespace("MAPI")

    set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")

    Set olParentFolder = olNs.PickFolder

    Set mymailbox = olParentFolder.Store

    Thursday, June 7, 2012 5:08 AM