Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...