#1
|
|||
|
|||
Reading msgs from specific inbox
Am trying to read email from Outlook. In VBA, I create an outlook session, then read the inbox with:
oSession.logon() oInbox = oSession.GetDefaultFolder(6) But if the user has more than one account, cannot figure how I can get the inbox for a specific account just using the email address or the account name. Any help greatly appreciated, Mark |
#2
|
||||
|
||||
You would need to identify the Store that contains the inbox e.g.
Code:
Dim oFolder As Folder Set oFolder = Session.Stores.Item("Name of Store").GetDefaultFolder(olFolderInbox)
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Quote:
Thanks, Have struggled with this, but this was very helpful. So "Name of Store" is the specific email address I wish to monitor. From that I can get the incoming msgs (item) in the inbox. A related question - Users will sometimes move a new msg from inbox to specially named folders like PastDueBill, Personal, etc. If they do so before I am able to pick up the new msgs in inbox, could you help me on the syntax for checking each of these other custom mailboxes they created? Also, how would I get the names of these other mailboxes they are using mostly for storage? Again, many thanks for clearing up this Store concept for me. Mark |
#4
|
||||
|
||||
You can loop through the stores and get their names and by adding them to a collection you can loop through the names e.g. as follows. However due to the many ways that Outlook can be configured, you may get duplicates. If the following shows duplicates with the same message counts then you can remove the duplicates by using. As you may not know what you are dealing with it may be better to simply leave the duplicates and process the folder twice.
Code:
oColl.Add oStore, oStore 'in place of oColl.Add oStore Code:
Sub Macro1() Dim oStore As Store Dim oFolder As Folder Dim oColl As Collection Dim i As Integer Set oColl = New Collection On Error Resume Next For Each oStore In Session.Stores Debug.Print oStore oColl.Add oStore Next oStore On Error GoTo 0 For i = 1 To oColl.Count Set oFolder = Session.Stores.Item(CStr(oColl(i))).GetDefaultFolder(olFolderInbox) 'do something with ofolder Debug.Print oFolder.Items.Count Next i lbl_Exit: Set oFolder = Nothing Set oStore = Nothing Set oColl = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
getdefaultfolder, reading mail |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Saved .msgs copies locked | asd12 | Outlook | 1 | 07-27-2018 06:32 AM |
Inbox rule to move everything from Junk to Inbox automatically? | sand3 | Outlook | 0 | 02-07-2017 12:38 PM |
How to stop OL from showing connection lost msgs.? | mmo | Outlook | 0 | 01-14-2016 04:33 AM |
Reading pane on TOP? | hehunt | Outlook | 0 | 04-10-2014 06:34 AM |
How to save a PPT file in 'Reading View' to be opened always in 'Reading View' | ItzVickey | PowerPoint | 2 | 08-08-2012 09:23 AM |