Sending Appointment through .NET

10 Sep

I had to create a Appointment by parsing through the database and then sending a particular guy a appointment which would remind him about the appointment approx 15 mins before the scheduled time. The same way in which Outlook Appointment functions.

Searching a bit, I found a way to utilise the Outlook Object library and send appointments by creating appointment objects and sending them.

Was damn happy with the outcome till I ran the program and then I saw the dreaded Prompt.
Due to a security protocol of MS ( Security patch ),everytime a code tried to create a instance of the Outlook object library and use it to send a mail, appoinment etc. it prompts the user with a dialog box asking him whether to allow access or to reject access to the program trying to use outlook object.

Now, since I was writing the code as a part of Windows Service there was no question of the prompt and letting the user click on the buttons every time code would send a appointment. Hence searching a bit on the outlooks Way of Forwarding Appoinments in ICalendar format and also the great Google 🙂
Found out a way of creating a ICalendar format Appointment and sending it accorss to the attendee.

Here is a way in which you can send appointments via ICalendar format through code and not using the Outlook Object library (This is a very basic version of the way and does not involve much exception handling,and doesnt take care of nth case , explore a bit on that front :))

posted Thursday, February 24, 2005 12:40 AM by Shaunakp with 2 Comments

SendAppointment Method ASP.NET ,ICalendar format
/// Sends a appointment in a ICalendar format.
/// Date of the meeting.
/// Start time of the meeting.
/// End time of the meeting.
/// Subject of the Meeting.
/// Name of the attendees for the meeting.
/// Email addresses of the attendess,seperated by ;.
/// Email address of the organizer.
/// Path of the current working directory.
/// bool indicating the status of the method call.
/// Need to give the current working directory path as the meeting request is
/// stored in the current directory before attaching it to the mail.
/// Will be adding more customisations in the parameters. and a class to encapsulate the parameter passing.
/// meetingRequest.CreateMeeting(“12/3/2004”,
///“12:30:00 PM”,
///“12:50:00 PM”,
///“Discuss demo issues”,
///“we need to have this meeting to discuss certain issues related to demo.”,
///“Conference room 1st floor”,
///shounak pandit,
///“c:\\prj\\temp”); currently requires the filepath to store the ICalendar file in.

public bool SendAppoinment(string startDate,
string startTime,
string endTime,
string subject,
string summary,
string location,
string attendeeName,
string attendeeEmail,
string organizerEmail,
string filePath)

const string c_strTimeFormat = “yyyyMMdd\\THHmmss\\Z”;
string strStartTime=””;
string strEndTime=””;
string strTimeStamp=””;
string strTempStartTime =””;
string strTempEndTime = “”;
string vCalendarFile = “”;

// VCalendar Format.
const string VCAL_FILE =
“VERSION:1.0\n” +
“DTSTART{0}\n” +
“DTEND{1}\n” +
“TRIGGER:-PT15M\n” +
“PRIORITY:3\n” +


DateTime dtmStartDate = DateTime.Parse(startDate.ToString());
DateTime dtmStartTime = DateTime.Parse(startDate + ” ” + startTime.ToString());
DateTime dtmEndTime = DateTime.Parse(startDate + ” ” + endTime.ToString());
strTempStartTime =
string.Format(“{0} {1}”,
strTempEndTime =
string.Format(“{0} {1}”,
strTimeStamp = (DateTime.Parse(strTempStartTime)).ToUniversalTime().ToString(c_strTimeFormat);
strStartTime =
string.Format(“:{0}”, strTimeStamp);
strEndTime =

vCalendarFile =
String.Format(VCAL_FILE, strStartTime, strEndTime, location, summary, subject , strTimeStamp, attendeeEmail.Trim() , “shaunak”, attendeeName.Trim(), attendeeEmail.Trim(), organizerEmail.Trim());

filePath += “\\” + subject+ “.ics”;
TextWriter tw =
new StreamWriter(filePath);

// write a line of text to the file

// close the stream

// Create object for sending mails

MailMessage mail = new MailMessage();
mail.To = attendeeEmail.Trim();
mail.From = organizerEmail.Trim();
mail.Subject = “You have got a Appointment.”;

// create the attachment
MailAttachment attachment = new MailAttachment(filePath, MailEncoding.UUEncode);
// Attach
mail.Attachments.Add( attachment );
SmtpMail.SmtpServer = _smtpServer;
SmtpMail.Send( mail );

catch (Exception ex)
throw new Exception(ex.Message + “for email address : ” + attendeeEmail.Trim() + “;”
return true;


1 Comment

Posted by on September 10, 2008 in .NET, Code Snippets


Tags: , , , ,

One response to “Sending Appointment through .NET

  1. Vinod

    December 6, 2012 at 10:30 AM

    is there anyway we can send the calendar invite without mentioning the SMTPServer, mean can we take the default SMTP configgured in IISU.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: