Read the body of a mail using VB6

K

Kam

Hi everyone,
I am trying to read mails which stores in a folder under "Public folders" on our server. I can walk through the folders but I don't know how to get the messages. I have inclosed my code, i hope it does help.

Looking forward to hearing from you soon.
Kam

================================================================
Dim ColMapiFolder As Outlook.Folders
Dim Mapifolder As Outlook.Mapifolder
Dim ColFolders As Outlook.Folders
Dim Folders As Outlook.Mapifolder
Dim ColMapiFolders2 As Outlook.Folders
Dim Mapifolder2 As Outlook.Mapifolder
Dim ColMapiFolders3 As Outlook.Folders
Dim MapiFolder3 As Outlook.Mapifolder
Dim ColMapiFolders4 As Outlook.Folders
Dim MapiFolder4 As Outlook.Mapifolder
Dim ColMapiFolders5 As Outlook.Folders
Dim MapiFolder5 As Outlook.Mapifolder
Dim ColMapiFolders6 As Outlook.Folders
Dim MapiFolder6 As Outlook.Mapifolder

Dim Treenode As Node

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("Mapi")
Set MySession = CreateObject("MAPI.Session")
Set ColMapiFolder = olNS.Folders

For Each Mapifolder In ColMapiFolder

If Mapifolder.Name = "Public Folders" Then
Set ColMapiFolders2 = Mapifolder.Folders

For Each Mapifolder2 In ColMapiFolders2
If Mapifolder2.Name = "YYY YYYYYY folders" Then
Set ColMapiFolders3 = Mapifolder2.Folders

For Each MapiFolder3 In ColMapiFolders3
If MapiFolder3.Name = "XXX QXXXXXX SXXXXX" Then
Set ColMapiFolders4 = MapiFolder3.Folders

For Each MapiFolder4 In ColMapiFolders4
If MapiFolder4.Name = "Accepted" Then
With tvMail.Nodes
Set Treenode = .Add(, , "root", MapiFolder4.Name, 1)

End With

Set ColMapiFolders5 = MapiFolder4.Folders
For Each MapiFolder5 In ColMapiFolders5
With tvMail.Nodes
Set Treenode = .Add("root", tvwChild, , MapiFolder5.Name, 1)
End With


Next

End If
Next
End If
Next
End If
Next
End If

Next
Set ColMapiFolders4 = Nothing
Set ColMapiFolders3 = Nothing
Set ColMapiFolders2 = Nothing
Set ColMapiFolder = Nothing
Set MySession = Nothing
Set olNS = Nothing
 
K

Ken Slovak - [MVP - Outlook]

Each folder has an Items collection. Iterate that collection and check
for each item being a MailItem. Every MailItem has a .Body property
that you can then get and parse.




Kam said:
Hi everyone,
I am trying to read mails which stores in a folder under "Public
folders" on our server. I can walk through the folders but I don't
know how to get the messages. I have inclosed my code, i hope it does
help.
Looking forward to hearing from you soon.
Kam

================================================================
Dim ColMapiFolder As Outlook.Folders
Dim Mapifolder As Outlook.Mapifolder
Dim ColFolders As Outlook.Folders
Dim Folders As Outlook.Mapifolder
Dim ColMapiFolders2 As Outlook.Folders
Dim Mapifolder2 As Outlook.Mapifolder
Dim ColMapiFolders3 As Outlook.Folders
Dim MapiFolder3 As Outlook.Mapifolder
Dim ColMapiFolders4 As Outlook.Folders
Dim MapiFolder4 As Outlook.Mapifolder
Dim ColMapiFolders5 As Outlook.Folders
Dim MapiFolder5 As Outlook.Mapifolder
Dim ColMapiFolders6 As Outlook.Folders
Dim MapiFolder6 As Outlook.Mapifolder

Dim Treenode As Node

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("Mapi")
Set MySession = CreateObject("MAPI.Session")
Set ColMapiFolder = olNS.Folders

For Each Mapifolder In ColMapiFolder

If Mapifolder.Name = "Public Folders" Then
Set ColMapiFolders2 = Mapifolder.Folders

For Each Mapifolder2 In ColMapiFolders2
If Mapifolder2.Name = "YYY YYYYYY folders" Then
Set ColMapiFolders3 = Mapifolder2.Folders

For Each MapiFolder3 In ColMapiFolders3
If MapiFolder3.Name = "XXX QXXXXXX SXXXXX" Then
Set ColMapiFolders4 = MapiFolder3.Folders

For Each MapiFolder4 In ColMapiFolders4
If MapiFolder4.Name = "Accepted" Then
With tvMail.Nodes
Set Treenode = .Add(, , "root", MapiFolder4.Name, 1)

End With

Set ColMapiFolders5 = MapiFolder4.Folders
For Each MapiFolder5 In ColMapiFolders5
With tvMail.Nodes
Set Treenode =
..Add("root", tvwChild, , MapiFolder5.Name, 1)
 
K

Kam

Thanks for your advice. Is there any way of getting the same format as body text? cause, when I get the body, it stickes all characters together.

Thanks in advance
 
K

Ken Slovak - [MVP - Outlook]

..HTMLBody is the property to use if the email is HTML. That will have
all the HTML tags and so on.




Kam said:
Thanks for your advice. Is there any way of getting the same format
as body text? cause, when I get the body, it stickes all characters
together.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top