vb: how to read outlook email?
This site provides users with the information about vb, visual basic, vb6, read outlook email, how to read outlook email, read email subject, retrieve email body, retrieve email sender, retrieve email receiver, and more.
If you think that this site is helpful, please recommend your friends to visit our site.
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") _
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
Set OlApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing