Creating a Task of Outlook in VB.NET

The following steps will help us to create the application.

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, click New, and then click Project.
  3. Click Visual Basic Projects under Project Types, and then click Console Application under Templates. By default, Module1.vb is created.
  4. Add a reference to the Microsoft Outlook 10.0/11.0 Object Library. To do this, follow these steps:
  • On the Project menu, click Add Reference.
  • On the COM tab, click Microsoft Outlook 10.0 Object Library, and then click Select.
  • Click OK in the Add References dialog box to accept your selections. If you are prompted to generate wrappers for the library that you selected, click Yes.

    5.  In the Code window, replace all of the code with the following:

Imports System.Reflection

Module Module1

    Sub Main()

        Try

 

            ' Create an Outlook application.

            Dim oApp As Outlook.Application = New Outlook.Application()

 

            ' Get NameSpace and Logon.

            Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi") oNS.Logon("Outlook", Missing.Value, FalseTrue)

 

            ' TODO: ' Create a new TaskItem.

            Dim OTask As Outlook.TaskItem = App.CreateItem(Outlook.OlItemType.olTaskItem)

 

            ' Assign the task

            OTask.Assign()

 

            ' Add recipients to the task

            OTask.Recipients.Add("[email protected]")

 

            ' Add the subject to the task

            OTask.Subject = "testing for SFA using code"

 

            'Add the body to the task

            OTask.Body = "tested by sridhar using code"

 

            ' Add the Task duedate

            OTask.DueDate = DateTime.Today

 

            ' Set the reminder to the task

            'oAppt1.ReminderSet = True

 

            ' Set the reminder time

            OTask.ReminderTime = OTask.DueDate

 

            ' If you want to display the task uncomment the next line

            'oAppt1.Display(True)

 

            ' Save the task to outlook

            OTask.Save()

 

            ' Send the task

            'oAppt1.Send()

 

        Catch ex As Exception

 

            Console.WriteLine(ex.Message)

 

        Finally

            ' Log off.

            oNS.Logoff()

 

            ' Clean up.

            oApp = Nothing

            oNS = Nothing

        End Try

    End Sub

 

End Module


    6.  Press F5 to build and run the program.
    7.  Verify that the appointment is created

Conclusion

The tasks have been now created and send through the mail using the Outlook and similarly various task/actions can be done using the Outlook dll and it can be said in the next article

Up Next
    Ebook Download
    View all
    Learn
    View all