RSS

Sending Appointment through .NET


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,
///shounakp@XYZ.com,
///shounak.pandit@ABC.com,
///"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 =
"BEGIN:VCALENDAR\n" +
"VERSION:1.0\n" +
"BEGIN:VEVENT\n" +
"DTSTART{0}\n" +
"DTEND{1}\n" +
"LOCATION;ENCODING=QUOTED-PRINTABLE:{2}\n" +
"DESCRIPTION;ENCODING=QUOTED-PRINTABLE:{3}\n" +
"SUMMARY;ENCODING=QUOTED-PRINTABLE:{4}\n" +
"TRIGGER:-PT15M\n" +
"PRIORITY:3\n" +
"END:VEVENT\n" +
"END:VCALENDAR" ;


try
{


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}",
dtmStartDate.ToShortDateString(),dtmStartTime.ToLongTimeString());
strTempEndTime =
string.Format("{0} {1}",
dtmStartDate.ToShortDateString(),dtmEndTime.ToLongTimeString());
strTimeStamp = (DateTime.Parse(strTempStartTime)).ToUniversalTime().ToString(c_strTimeFormat);
strStartTime =
string.Format(":{0}", strTimeStamp);
strEndTime =
string.Format(":{0}",
(DateTime.Parse(strTempEndTime)).ToUniversalTime().ToString(c_strTimeFormat));


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
tw.WriteLine(vCalendarFile.ToString());


// close the stream
tw.Close();


// 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() + ";"
,ex.InnerException);
}
return true;
}


)



  1. Vinod

    December 6, 2012 at 5: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.

  1. Vinod

    December 6, 2012 at 5: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.

Post a Comment

Copyright © Shounak S. Pandit. Powered by Blogger.

Ads