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

  • Thread starter Thread starter DPM
  • Start date Start date
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.
 
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.
 
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.
 
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-


 
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


-
>

>
 
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
M Outlook 365 Amending code so macro runs within current new mail window Outlook VBA and Custom Forms 0
O Junk E-mail Options disabled(?) Using Outlook 3
E Replying to a plain text e-mail with HTML Using Outlook 2
P Limited Support for 3rd Party Mail in new Outlook? Using Outlook 1
T Exchange Server - Mail Delay Stamping Exchange Server Administration 0
L Error when exporting Sent Mail to Excel Outlook VBA and Custom Forms 6
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
K How can I delete an e-mail from Outlook Using Outlook 1
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
A Macro Mail Alert Using Outlook 4
e_a_g_l_e_p_i MY Outlook 2021 changed the format of the shortcuts for mail, calendar etc. Using Outlook 10
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
P What is your strategy for dealing with SPAM and Junk Mail? Using Outlook 1
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
T 1:1 Datatransfer from incoming mail body to customs form body Outlook VBA and Custom Forms 0
O Mail rule issue Using Outlook 3
A manual rule sends mail to wrong folder Using Outlook 5
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
D Outlook 2003 Mail Fails Using Outlook 1
Cathy Rhone Mail merge error message Using Outlook 1
R Sent emails show iCloud mail account not the alias Using Outlook 2
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
P Importing other e-mail accounts into Outlook Using Outlook 1
lcarpay Stay in the mail folder pane after ctrl-1 Using Outlook 1
O Exchange Sync period only (e.g. last years mail) Using Outlook 0
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
M Convertor for Outlook Express Mail Store (.dbx) to Outlook Mail Store (.pst) Using Outlook 0
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
J E-mail held in Outbox while Minimized Using Outlook 3
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
T Outlook creates a copie of every mail I send Using Outlook.com accounts in Outlook 4
N Please advise code received new mail Using Outlook 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

Similar threads

Back
Top