i posted the question on how to get emails from my inbox and i received the code at the bottom of this post. now the problem is that this only works if outlook is open. how do i call the inbox when outlook is closed?
Imports System.Reflection
Module Module1
Sub Main()
Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
Get Mapi NameSpace.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) TODO:
Get Messages collection of Inbox.
Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Outlook.Items = oInbox.Items
Console.WriteLine("Total : " & oItems.Count)
Get unread e-mail messages.
oItems = oItems.Restrict("[Unread] = true")
Console.WriteLine("Total Unread : " & oItems.Count)
Loop each unread message.
Dim oMsg As Outlook.MailItem
Dim i As Integer
For i = 1 To oItems.Count
oMsg = oItems.Item(i)
Console.WriteLine(i)
Console.WriteLine(oMsg.SenderName)
Console.WriteLine(oMsg.Subject)
Console.WriteLine(oMsg.ReceivedTime)
Console.WriteLine(oMsg.Body)
Console.WriteLine("---------------------------")
Next
Log off.
oNS.Logoff()
Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing
End Sub
End Module
Imports System.Reflection
Module Module1
Sub Main()
Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
Get Mapi NameSpace.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) TODO:
Get Messages collection of Inbox.
Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Outlook.Items = oInbox.Items
Console.WriteLine("Total : " & oItems.Count)
Get unread e-mail messages.
oItems = oItems.Restrict("[Unread] = true")
Console.WriteLine("Total Unread : " & oItems.Count)
Loop each unread message.
Dim oMsg As Outlook.MailItem
Dim i As Integer
For i = 1 To oItems.Count
oMsg = oItems.Item(i)
Console.WriteLine(i)
Console.WriteLine(oMsg.SenderName)
Console.WriteLine(oMsg.Subject)
Console.WriteLine(oMsg.ReceivedTime)
Console.WriteLine(oMsg.Body)
Console.WriteLine("---------------------------")
Next
Log off.
oNS.Logoff()
Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing
End Sub
End Module