Click here to Skip to main content
13,796,889 members
Click here to Skip to main content
Add your own
alternative version


1 download
41 bookmarked
Posted 24 Jul 2005

Sending Tasks Programmatically

, 24 Jul 2005
Rate this:
Please Sign up or sign in to vote.
This article shows two different ways of sending tasks programmatically. One is using the Microsoft Outlook 11.0 Object Library and the other is using vCalendar.


I’m going to show two different ways of sending tasks programmatically. One is using the Microsoft Outlook 11.0 Object Library and the other is using vCalendar.

Using Microsoft Outlook 11.0 Object Library

The simplest of these is using Microsoft 11.0 object library. This has a class called TaskItem. TaskItem represents a task (an assigned, delegated, or self-imposed task to be performed within a specified time frame) in a Tasks folder. Like appointments or meetings, tasks can be delegated. You can get this library from Add Reference and click on COM tab.

Create an alias as follows:

using Outlook = Microsoft.Office.Interop.Outlook;

Create objects of ApplicationClass and TaskItem as follows:

Outlook.ApplicationClass app = new Outlook.ApplicationClass();
Outlook.TaskItem tsk = (Outlook.TaskItem) 

Set the properties of task as needed:

tsk.StartDate = DateTime.Now;
tsk.DueDate = DateTime.Now;
tsk.Subject = "Test";
tsk.Body = "Testing Task";

That’s it. This is the simplest way for creating and sending a task programmatically. One disadvantage of this is we get to click away the annoying security popups.

Using vCalendar

The next way is through the vCalendar object. vCalendar is the industry standard format for sending/receiving scheduling information electronically. vCalendar was developed by a consortium formed by IBM, AT&T, Siemens and Apple. Later, this specification was given to Internet Mail Consortium. Now, most of the Personal Information Manager (PIM) programs on all software support vCalendar as the standard exchange format.

Microsoft Outlook supports vCalendar (what more do we want ;)). vCalendar files are not just used to exchange appointments and schedules within one organization. They can be used to schedule appointments with others, who use scheduling software incompatible with yours (all the more we want, right?). Let’s get on with how to create a vCalendar object programmatically.

vCalendar file would look something like the following:

BEGIN:VCALENDAR PRODID:-//Microsoft Corporation//Outlook MIMEDIR//EN 
     VERSION:1.0 BEGIN:VEVENT DTSTART:19980114T210000Z DTEND:19980114T230000Z 
     LOCATION:Team Room CATEGORIES:Business 

To create the vCalendar object, we have the method given below:

string CreateTask(DateTime start, DateTime end, string sub, string msgBody)
    StringBuilder sbvCalendar = new StringBuilder();

    sbvCalendar.Append("METHOD: REQUEST");
    sbvCalendar.Append("PRODID:-//Microsoft Corporation//Outlook ");
    string hour = start.Hour.ToString();
    if(hour.Length<2){hour ="0"+ hour;}
    string min = start.Minute.ToString();
    if(min.Length<2){min = "0" + min;}
    string sec = start.Second.ToString();
    if(sec.Length<2){sec = "0" + sec;}

    string mon = start.Month.ToString();
    if(mon.Length<2){mon ="0" + mon;}
    string day = start.Day.ToString();
    if(day.Length<2){day ="0" + day;}

    sbvCalendar.Append(start.Year.ToString()+ mon + day 
                           +  "T" + hour + min + sec );

    hour = end.Hour.ToString();
    if(hour.Length<2){hour ="0"+ hour;}

    min = end.Minute.ToString();
    if(min.Length<2){min = "0" + min;}
    sec = end.Second.ToString();
    if(sec.Length<2){sec = "0" + sec;}

    mon = end.Month.ToString();
    if(mon.Length<2){mon ="0" + mon;}
    day = end.Day.ToString();
    if(day.Length<2){day ="0" + day;}

    sbvCalendar.Append(end.Year.ToString()+ mon + 
                 day +  "T" + hour + min + sec );

                                             + String.Empty);
    //Message body
                                                    + msgBody);

                                                    + sub);

    return sbvCalendar.ToString();

We can use this method as:

string sub = "Test";
string body = "Testing Task";

//Create a message object
MailMessage msg = new MailMessage();
msg.From = "";
msg.To = "";
msg.Subject = sub;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.Body = body;
//Set the date/time
DateTime start = DateTime.Parse("Jan 1, 2005");
DateTime end = DateTime.Parse("Jan 2, 2005");
DateTime ex = DateTime.Now;

//Location where you want to save the vCalendar file
string attachUrl = 
   "C:\Inetpub\wwwroot\WebApplication3\bin\ Test.vcs";

//Create task
using(StreamWriter sw = new StreamWriter(attachUrl)
  sw.Write(CreateTask (start, end, sub, body));

//Attach the task
MailAttachment mAttachment = new MailAttachment(attachUrl);
SmtpMail.SmtpServer = "";

That’s it. Happy coding!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Mercy Ponnupandy
United States United States
Architect / Consultant on Content Management and Cloud Computing... Artist and Author by the weekends...

You may also be interested in...

Comments and Discussions

QuestionYou can also do this with EWS. Pin
ayseff2-Dec-14 17:14
memberayseff2-Dec-14 17:14 
GeneralNice Article Pin
Rajin Sayeed S Alam15-May-11 20:07
memberRajin Sayeed S Alam15-May-11 20:07 
GeneralMy vote of 3 Pin
fertansa2-Mar-11 12:21
memberfertansa2-Mar-11 12:21 
Newsbroken code - do not use as-is - please read the RFC and validate Pin
rlively6-Apr-10 9:16
memberrlively6-Apr-10 9:16 
GeneralRe: broken code - do not use as-is - please read the RFC and validate Pin
Member 1028103925-Feb-14 0:22
memberMember 1028103925-Feb-14 0:22 
Generalmsg.To cannot be assigned Pin
James_Lin11-May-09 11:12
memberJames_Lin11-May-09 11:12 
GeneralAppending strings to get vCalendar: wrong, Using MS API: right Pin
rlively10-Oct-08 6:40
memberrlively10-Oct-08 6:40 
GeneralReminder & Busy Status Pin
Member 44677752-Oct-08 4:56
memberMember 44677752-Oct-08 4:56 
QuestionAppointment vs Task Pin
centric5-Mar-07 8:57
membercentric5-Mar-07 8:57 
GeneralHave a little problem Pin
uddesh14-Feb-07 19:37
memberuddesh14-Feb-07 19:37 
GeneralRe: Have a little problem Pin
Filip C2-Apr-09 2:43
memberFilip C2-Apr-09 2:43 
GeneralOther people's tasks Pin
Kokas1-Nov-05 3:10
memberKokas1-Nov-05 3:10 
GeneralRe: Other people's tasks Pin
stehlewm21-Jul-06 5:43
memberstehlewm21-Jul-06 5:43 
QuestionAnd with no attachment? Pin
joujoukinder1-Sep-05 21:51
memberjoujoukinder1-Sep-05 21:51 
QuestionOutlook neets to run in background ? Pin
mvanschie27-Jul-05 23:12
membermvanschie27-Jul-05 23:12 
AnswerRe: Outlook neets to run in background ? Pin
stehlewm21-Jul-06 5:37
memberstehlewm21-Jul-06 5:37 
GeneralNice, But... Pin
FZelle25-Jul-05 5:52
memberFZelle25-Jul-05 5:52 
It's a nice article but why do you use so much code to format the DateTime?
<br />
string hour = start.Hour.ToString();<br />
    if(hour.Length<2){hour ="0"+ hour;}<br />
            <br />
    string min = start.Minute.ToString();<br />
    if(min.Length<2){min = "0" + min;}<br />
            <br />
    string sec = start.Second.ToString();<br />
    if(sec.Length<2){sec = "0" + sec;}<br />
<br />
    string mon = start.Month.ToString();<br />
    if(mon.Length<2){mon ="0" + mon;}<br />
             <br />
    string day = start.Day.ToString();<br />
    if(day.Length<2){day ="0" + day;}<br />
<br />
    sbvCalendar.Append(start.Year.ToString()+ mon + day <br />
                           +  "T" + hour + min + sec );<br />

Could become:
<br />
  sbvCalendar.Append(start.ToString("yyyyMMddTHHmmss"))<br />

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.181207.3 | Last Updated 25 Jul 2005
Article Copyright 2005 by Mercy Ponnupandy
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid