ARTICLE

Creating a Task in Outlook

Posted by Sridhar Manoharan Articles | Visual Basic 2010 July 02, 2007
This article helps us to create a new task in Microsoft Outlook and send it through a mail.
 
Reader Level:

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, 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("sridhar@yahoo.com")

 

            ' 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.

Login to add your contents and source code to this article
share this article :
post comment
 

This is a great article!  Thanks!

I have one question though:  How do I save a task to a users task list without them having to accept it in exchange?  This is part of an automated process which assings tasks to users depending on the certain project creations.

Do I need to provide the exchange admin credentials?  Do I do this in this snippet?

oNS.Logon("Outlook", Missing.Value, false, true); --> oNS.Logon("adm_id", "adm_pwd", false, true);

Posted by John Lombardo Nov 24, 2009

Thanks Sridhar, your article helped me in adding tasks in outlook via my VB.NET application. After adding the task, when I open my outlook, I can see the created task in ToDo, Task List & in Say & Week of Calendar but not in Month of Calendar View. Any idea how can I see the task in Month view too. And on mouse over of the task, I want to see the body of the task in a window, like we can see the Start Time, End Time, etc .I want to see the body part of the task. How Can I see that full contents. If you have any idea to solve any or my both points, would be greatful. Thanks Once again.

Posted by Terry Feb 18, 2009
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor