purav topiwala purav topiwala - 2 years ago 164
Vb.net Question

I want to show Outlook mail body Template in vb.net form

I want to display my outlook Inbox in my vb.net form with navigation like

<< Prev Next>>>

mail body must contain outlook template and display with all useful content like

  1. SenderName

  2. SenderEmail

  3. Datetime

  4. CC

  5. Attchment (if any)

Please help me if anyone have idea about it.

Thanks in advance.

Answer Source

1st result google gave me: (modified a little) The basis is there, you can start experimenting. At least try to create something yourself, than do a repost along with the code you have tried.

Imports System.Reflection Imports Microsoft.Office.Interop

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 = oItems.Count To 1 Step -1
        oMsg = oItems.Item(i)


    ' Log off.

    ' Clean up.
    oApp = Nothing
    oNS = Nothing
    oItems = Nothing
    oMsg = Nothing
End Sub

End Module

Display in Form:

Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim oApp As New Outlook.Application
    Dim mitem As Outlook.MailItem
    mitem = oApp.CreateItemFromTemplate("\\Files\HC_METOD\SVA\meeting.msg")
    WebBrowser1.DocumentText = mitem.HTMLBody
End Sub
End Class
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download