Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading contents of a mail from Outlook?

Status
Not open for further replies.

Chotor

Technical User
Oct 2, 2008
20
NO
I want to read a specific mail (arriving every day) from my Inbox.
This mail is uniquely identifiable by for example sender.
Also, I have this mail item open.

How can I read a specific mail? Preferably the one I have open.

Thanks to another poster, I have this:
Code:
Dim thisApp As Object, thisNameSpace As Object, thisFolder As Object, theseItems As Object, mailBody As Object
Set thisApp = GetObject("","Outlook.Application")
Set thisNameSpace = thisApp.GetNamespace("MAPI")
Set thisFolder = thisNameSpace.Folders("Mailbox - Lastname, Firstname")
Set theseItems = thisFolder.Folders("Inbox").Items(4)  <-- this is an example, which brings a correct mail from some days ago

Msgbox "Item: "+Str$(theseItems)

I would like to specify a specific mail, and then read it's contents.
 
'For mm=1 to restitems2.count
olSubject=restitems2.item(mm).Subject
or
olSubject=restitems2.item(mm).body
 
Thanks. After some programming, I'm now able to read the mail's contents (body).

I'm using
Code:
Set theseItems = thisFolder.Folders("Inbox").Items(4)

Dim lineJPY As String
Dim HeMail As String

HeMail = theseItems.Body
lineJPY = ExtractToCR(HeMail, "JPY")

Msgbox "JPY: "+lineJPY
ExtractToCR is just a function I made, reading a substring from a larger string.

The problem now is:
How do I read a specific mail?

Maybe one solution would be to sort those pertaining mails to a folder, and read the newest item from there?
 
Instead of spamming the forum with a new thread, I'm trying to ask here first.

How do I read a specific mail?

I know who sends it (I recieve one every day) and the subject.
I want to read today's email from this person.
 
Here's something for you to play with.
Code:
Option Explicit

Sub Main()
   Dim obj_ol As Object, obj_ns As Object, obj_inbox As Object
   Dim obj_filtered_items As Object, obj_mail_item As Object
   Dim i As Integer

   Set obj_ol             = CreateObject("Outlook.Application")
   Set obj_ns             = obj_ol.GetNamespace("MAPI")
   Set obj_inbox          = obj_ns.GetDefaultFolder(6)
   Set obj_filtered_items = obj_inbox.Items.Restrict("[From] = 'John Doe'")

   If obj_filtered_items.Count > 0 Then
      For i = obj_filtered_items.Count To 1 Step -1
         Set obj_mail_item = obj_filtered_items(i)

         MsgBox "SUBJECT:  " & obj_mail_item.subject & chr(13) & "BODY:  " & obj_mail_item.body
      Next i
   End If

   Set obj_mail_item      = Nothing
   Set obj_filtered_items = Nothing
   Set obj_inbox          = Nothing
   Set obj_ns             = Nothing
   Set obj_ol             = Nothing
End Sub
 
Nice, thanks. I'll keep this for reference.
I actually accomplished what I wanted to do antoher way:

I move those mails into a separate folder (with Outlook). What I discovered is that Outlook indexes mails in a folder from 1 to n, 1 being the oldest item and n is the newest item. So what I do is just count the items in the pertaining folders, and grab the last item.

Code:
i = thisFolder.Folders("DAB").Items.Count
Set theseItems = thisFolder.Folders("DAB").Items(i)
mail_content = theseItems.Body

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top