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:

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, False, True)

' 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