opening outlook

jasonseay

Active member
Joined
Jun 17, 2003
Messages
29
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
 
i finally got it to work

changed line:

ons.logon("yourvalidprofile", missing.value, false, true)

to:

ons.logon(<emailaddress>, <password>, false, true)
 
Back
Top