How to identify a mail item from a public folder in MS Outlook

Status
Not open for further replies.
D

DPM

Hi,

I have developed an application which read mails from a user selected folder

of MS Outlook.

Following is a code sample.

loOutlookSession = CREATEOBJECT("OutLook.Application")

loNameSpace = loOutlookSession.GetNameSpace("MAPI")

loMailFolder = loNameSpace.PickFolder()

IF loMailFolder.DefaultItemType = 0

** This is a folder with mail items

ENDIF

This works fine as long as a mail folder is selected but if the user selects

a public folder it does not imports its mails as the public folder's

DefaultItemType property returns 6.

I noticed that these public folders could have items other than mails, such

as tasks, contacts, ect..

Therefore even if public folders are allowed to import mails from it, it

fails when there are non mail items in the public folder.

To avoid this could someone please advice how to identify a mail item from

the rest of the non mail items in the public folder.
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Instead of checking the folder's DefaultItemType property, you can check

each item's object type. For instance:

Dim obj as Object

For Each obj in Items

If Typeof obj is Outlook.MailItem Then ...

Next

Best regards

Michael Bauer

Am Tue, 10 Nov 2009 10:16:53 +0530 schrieb DPM:


> Hi,

> I have developed an application which read mails from a user selected


folder
> of MS Outlook.
> Following is a code sample.

> loOutlookSession = CREATEOBJECT("OutLook.Application")
> loNameSpace = loOutlookSession.GetNameSpace("MAPI")
> loMailFolder = loNameSpace.PickFolder()
> IF loMailFolder.DefaultItemType = 0
> ** This is a folder with mail items
> ENDIF

> This works fine as long as a mail folder is selected but if the user


selects
> a public folder it does not imports its mails as the public folder's
> DefaultItemType property returns 6.

> I noticed that these public folders could have items other than mails,


such
> as tasks, contacts, ect..
> Therefore even if public folders are allowed to import mails from it, it
> fails when there are non mail items in the public folder.

> To avoid this could someone please advice how to identify a mail item from
> the rest of the non mail items in the public folder.
 
D

DPM

Thanks Michael,

Also found that the Class property returns 43 for a MailItem

"Michael Bauer " <mb@mvps.org> wrote in message

news:h56ytjpn3c14.6qdv44grfkcn$.dlg@40tude.net...

> Instead of checking the folder's DefaultItemType property, you can check
> each item's object type. For instance:

> Dim obj as Object
> For Each obj in Items
> If Typeof obj is Outlook.MailItem Then ...
> Next

> > Best regards
> Michael Bauer

> >

> Am Tue, 10 Nov 2009 10:16:53 +0530 schrieb DPM:
>
> > Hi,
>

>> I have developed an application which read mails from a user selected

> folder
> > of MS Outlook.
> > Following is a code sample.
>

>> loOutlookSession = CREATEOBJECT("OutLook.Application")
> > loNameSpace = loOutlookSession.GetNameSpace("MAPI")
> > loMailFolder = loNameSpace.PickFolder()
> > IF loMailFolder.DefaultItemType = 0
> > ** This is a folder with mail items
> > ENDIF
>

>> This works fine as long as a mail folder is selected but if the user

> selects
> > a public folder it does not imports its mails as the public folder's
> > DefaultItemType property returns 6.
>

>> I noticed that these public folders could have items other than mails,

> such
> > as tasks, contacts, ect..
> > Therefore even if public folders are allowed to import mails from it, it
> > fails when there are non mail items in the public folder.
>

>> To avoid this could someone please advice how to identify a mail item
> > from
> > the rest of the non mail items in the public folder.
 
J

JP

To add to what Michael wrote, use a custom function for this. i.e.

Function IsMailItem(Itm As Object) As Boolean

IsMailItem = (Typeof Itm is Outlook.MailItem)

End Function

Then call the function in your loop:

Dim obj as Object

For Each obj in Items

If IsMailItem(obj) Then ...

Next obj

--JP

On Nov 10, 7:56 am, "DPM" <a...@bb.cc> wrote:
> Thanks Michael,
> Also found that the Class property returns 43 for a MailItem

> "Michael Bauer " <m...@mvps.org> wrote in messagenews:h56ytjpn3c14.6qdv44grfkcn$.dlg@40tude.net...

>
> > Instead of checking the folder's DefaultItemType property, you can check
> > each item's object type. For instance:

>
> > Dim obj as Object
> > For Each obj in Items
> > If Typeof obj is Outlook.MailItem Then ...
> > Next

>
> > > > Best regards
> > Michael Bauer

>
> >  > >  > >  

>
> > Am Tue, 10 Nov 2009 10:16:53 +0530 schrieb DPM:

>
> >> Hi,

>
> >> I have developed an application which read mails from a user selected

> > folder
> >> of MS Outlook.
> >> Following is a code sample.

>
> >> loOutlookSession = CREATEOBJECT("OutLook.Application")
> >> loNameSpace = loOutlookSession.GetNameSpace("MAPI")
> >> loMailFolder = loNameSpace.PickFolder()
> >> IF loMailFolder.DefaultItemType = 0
> >>     ** This is a folder with mail items
> >> ENDIF

>
> >> This works fine as long as a mail folder is selected but if the user

> > selects
> >> a public folder it does not imports its mails as the public folder's
> >> DefaultItemType property returns 6.

>
> >> I noticed that these public folders could have items other than mails,

> > such
> >> as tasks, contacts, ect..
> >> Therefore even if public folders are allowed to import mails from it, it
> >> fails when there are non mail items in the public folder.

>
> >> To avoid this could someone please advice how to identify a mail item
> >> from
> >> the rest of the non mail items in the public folder.- Hide quoted text-


 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
What an overhead.

Best regards

Michael Bauer

Am Tue, 10 Nov 2009 05:46:54 -0800 (PST) schrieb JP:


> To add to what Michael wrote, use a custom function for this. i.e.

> Function IsMailItem(Itm As Object) As Boolean
> IsMailItem = (Typeof Itm is Outlook.MailItem)
> End Function

> Then call the function in your loop:

> Dim obj as Object
> For Each obj in Items
> If IsMailItem(obj) Then ...

> Next obj

> --JP

> On Nov 10, 7:56 am, "DPM" <a...@bb.cc> wrote:
> > Thanks Michael,
> > Also found that the Class property returns 43 for a MailItem
>

>> "Michael Bauer " <m...@mvps.org> wrote in


messagenews:h56ytjpn3c14.6qdv44grfkcn$.dlg@40tude.net...
>

>
>
>
>>
> >> Instead of checking the folder's DefaultItemType property, you can check
> >> each item's object type. For instance:

> >
> >> Dim obj as Object
> >> For Each obj in Items
> >> If Typeof obj is Outlook.MailItem Then ...
> >> Next

> >
> >> > >> Best regards
> >> Michael Bauer

> >
> >>  >>>  >>>  

> >
> >> Am Tue, 10 Nov 2009 10:16:53 +0530 schrieb DPM:

> >
> >>> Hi,

> >
> >>> I have developed an application which read mails from a user selected
> >> folder
> >>> of MS Outlook.
> >>> Following is a code sample.

> >
> >>> loOutlookSession = CREATEOBJECT("OutLook.Application")
> >>> loNameSpace = loOutlookSession.GetNameSpace("MAPI")
> >>> loMailFolder = loNameSpace.PickFolder()
> >>> IF loMailFolder.DefaultItemType = 0
> >>>     ** This is a folder with mail items
> >>> ENDIF

> >
> >>> This works fine as long as a mail folder is selected but if the user
> >> selects
> >>> a public folder it does not imports its mails as the public folder's
> >>> DefaultItemType property returns 6.

> >
> >>> I noticed that these public folders could have items other than mails,
> >> such
> >>> as tasks, contacts, ect..
> >>> Therefore even if public folders are allowed to import mails from it,


it
> >>> fails when there are non mail items in the public folder.

> >
> >>> To avoid this could someone please advice how to identify a mail item
> >>> from
> >>> the rest of the non mail items in the public folder.- Hide quoted text


-
>

>
 
J

JP

It's encapsulation, Michael. Besides, it's not going to change the

number of iterations.

--JP

On Nov 10, 3:54 pm, "Michael Bauer " <m...@mvps.org
wrote:
> What an overhead.

> > Best regards
> Michael Bauer

>   >   >  

> Am Tue, 10 Nov 2009 05:46:54 -0800 (PST) schrieb JP:

>
> > To add to what Michael wrote, use a custom function for this. i.e.

>
> > Function IsMailItem(Itm As Object) As Boolean
> >   IsMailItem = (Typeof Itm is Outlook.MailItem)
> > End Function

>
> > Then call the function in your loop:

>
> > Dim obj as Object
> > For Each obj in Items
> >   If IsMailItem(obj) Then ...

>
> > Next obj

>
> > --JP

>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S Correct way to Identify is Mail is opened in Edit Mode Outlook VBA and Custom Forms 1
I Identify Number of email messages opened Outlook VBA and Custom Forms 7
S VBA to identify a specific email and copy the attachment from it to the network Outlook VBA and Custom Forms 4
M Best way to identify/designate contacts in incoming emails? Using Outlook 4
makinmyway How can I easily identify and delete from my contacts defunct email addresses? Using Outlook 2
G How can I identify in VBA if the current window is an item or a folder? Using Outlook 3
S Identify weekend from daily RecurrencePattern Outlook VBA and Custom Forms 2
S Identify Read Recepits Outlook VBA and Custom Forms 7
H Better way of writing Macro? Identify multiple types of attachmen Outlook VBA and Custom Forms 5
N Please advise code received new mail Using Outlook 0
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0
A How to stop user form from disapearing once mail window is closed? Outlook VBA and Custom Forms 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
R How to Sync *all* Google Workspace Mail Folders with Outlook 2019 (MS365) Using Outlook 3
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
L Correct E-Mail Pulling Wrong Mail Using Outlook 5
S Outlook mail adressing stops after first match in GAL Using Outlook 0
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
MrMayor SENT mail not reloading to top?? Using Outlook 4
Terry Sullivan Sender Field Displays My E-Mail Address, Not My Name Using Outlook 1
ThinkToday Calculate reply time of outlook mail Using Outlook 1
B Outlook 2010 Opening Mail Attachment Using Outlook 2
e_a_g_l_e_p_i Is it possible it set the fonts used to read incoming mail Using Outlook 25
D Mail in Sent Items Gone Using Outlook 12
M Managing Gmail "All Mail" sync issues with IMAP Using Outlook 1
GregS Outlook 2016 Sent Mail absent from Sent Mail or Sent Items Folders Using Outlook 4
GregS Why is Outlook 2016 mail in Outlook.com? Using Outlook 1
S Outlook not receiving mail Using Outlook 1
Commodore Outlook (2013) issues with icloud.com mail Using Outlook 0
GregS Outlook 2016 iPhone won't download Outlook 2016 Mail. Using Outlook 0
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
oliv- How to distinguish whether mail is incoming or outgoing? Outlook VBA and Custom Forms 2
W Receiving mail for account that has been deleted Using Outlook 2
H In outlook 365 POP mail Inbox, email takes a long time or never arrives. Using Outlook 1
Z Add text to auto-forwarded e-mail Outlook VBA and Custom Forms 4
K HOW TO FIX AOL MAIL ISSUES? Using Outlook 0
O How to prevent CC from showing when creating a new mail? Using Outlook 1
I Junk Mail and PersonMetadata Using Outlook 2
T 3 months of archived e-mail is missing Using Outlook 1
B Outlook - Mail from safe senders list being sent to Spam Folder Using Outlook 0
G Detect Google Drive and OneDrive links in incoming mail Outlook VBA and Custom Forms 3
M Sent mail not showing in Sent Items folder; but they can be found with Search Using Outlook 3
H Outlook 2016 sent over 30 copies of an e-mail with attachments Using Outlook 1
T Missing text in e-mail message after "(Please keep confidential)" Using Outlook 3
Victor_50 Outlook 2013 Custom Contact Form starts with "E-mail 2" Outlook VBA and Custom Forms 2
E Mail sorting view issue Using Outlook 1

Similar threads

Top