Microsoft Outlook 11.0 Object Library

G

Guest

I am retrieving message from the Inbox as follows: (MS Article ID 310258: How
to use the Microsoft Outlook Object Library to retrieve a message from the
Inbox by using Visual C# .NET)

Try
Dim oApp As Outlook.Application = New Outlook.Application
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon(Missing.Value, Missing.Value, False, True)
Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Outlook.Items = oInbox.Items
Dim oMsg As Outlook.MailItem = CType(oItems.GetFirst, Outlook.MailItem)
Console.WriteLine(oMsg.Subject)
Console.WriteLine(oMsg.SenderName)
Console.WriteLine(oMsg.ReceivedTime)
Console.WriteLine(oMsg.Body)

Dim AttachCnt As Integer = oMsg.Attachments.Count

oMsg.Attachments.Item(1).SaveAsFile("C:\Temp\Attach")
Console.WriteLine("Attachments: " + AttachCnt.ToString)
If AttachCnt > 0 Then
Dim i As Integer = 1
While i <= AttachCnt
Console.WriteLine(i.ToString + "-" + oMsg.Attachments(i).DisplayName)
System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
End While
End If
oMsg.Display(True)
oNS.Logoff()
oMsg = Nothing
oItems = Nothing
oInbox = Nothing
oNS = Nothing
oApp = Nothing
Catch e As Exception
Console.WriteLine("{0} Exception caught: ", e)
End Try

When I run the sample I get a message box saying "A program is trying to
access e-mail addresses you have stored in Outlook. Do you want to allow
this? If this unexpected, it may b a virus and you should choose "No"." How
can I turn off this message box?

Secondly, how can I save the attached rather than opening the email?

Is there any document that describes methods and properties exposed by
Microsoft Outlook Object Library? I could not find any link. Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top