chitika

Sunday, September 11, 2011

How to how to read outlook email?

The following program is used to read unread emails with email subject, email body, email sender, and email receiver from outlook and add them to a text file for later use and the code is as follows:


--------------------------------------------------------------------------------
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object

Shell "c:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"
Open App.Path & "\temp.txt" For Output As #1

'maybe need sleep(3000) function

Set OlApp = CreateObject("Outlook.Application")
'Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set Inbox = OlApp.GetNamespace("Mapi").Folders("Personal Folders") _
.Folders("Inbox")

Set InboxItems = Inbox.Items

For Each Mailobject In InboxItems
If Mailobject.UnRead Then
Print #1, Mailobject.Body
'Print #1 = Mailobject.Subject
'Print #1 = Mailobject.SenderName
'Print #1 = Mailobject.To
'Print #1 = Mailobject.Body
'Print #1 = Mailobject.SentOn
Mailobject.UnRead = False
End If
DoEvents
Next

Set OlApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing

Close #1

No comments:

Post a Comment

For other hundreds of computer repair tips, tricks, tweaks, guide, help, please go to


http://website.edusoftmax.com