Click here to Skip to main content
Licence CPOL
First Posted 31 Mar 2008
Views 48,333
Downloads 910
Bookmarked 42 times

Send Appointment Through Mail in ASP.NET

By | 31 Mar 2008 | Article
Send appointment or event through mail, so it can be synchronized with Outlook calendar
event1.png

Introduction

Nowadays, event management is becoming a very popular idea especially in case of web application development. Most of the application is synchronizing with Outlook contacts and calendar. Here is a small tool to create events, both hour events and day events. This concept is very simple creating an ICS file and sending as mail attachment.

Background

I was developing a web application which is related to event management and my client requirement is to send day and hour events so it will be synchronized with client’s Outlook calendar.

Send Event/Appointment

In Outlook, two types of events/appointments can be sent.

  1. Hourly event (based on specific hour of a day)
  2. Day event (based on specific days)

Hourly Event

To send hourly event, you need to send ics file for hour event. ICS file looks like that:

cal_hour_event.png

I have made a simple UI to send hour event. To load hour, use a simple control from AjaxControlToolkit. This is the simple UI.

hour_event.png

Code to create ICS file for day event/appointment:

public string MakeHourEvent(string subject, string location, 
	DateTime date, string startTime, string endTime)
   {
    string filePath = string.Empty;
    string path = HttpContext.Current.Server.MapPath(@"\iCal\");
    filePath = path + subject + ".ics";
    writer = new StreamWriter(filePath);
    writer.WriteLine("BEGIN:VCALENDAR");
    writer.WriteLine("VERSION:2.0");
    writer.WriteLine("PRODID:-//hacksw/handcal//NONSGML v1.0//EN");
    writer.WriteLine("BEGIN:VEVENT");
    string startDateTime = GetFormatedDate(date)+"T"+GetFormattedTime(startTime);
    string endDateTime = GetFormatedDate(date) + "T" + GetFormattedTime(endTime);
    writer.WriteLine("DTSTART:" + startDateTime);
    writer.WriteLine("DTEND:" + endDateTime);
    writer.WriteLine("SUMMARY:" + subject);
    writer.WriteLine("LOCATION:" + location);
    writer.WriteLine("END:VEVENT");
    writer.WriteLine("END:VCALENDAR");
    writer.Close();
    return filePath;
   }

Daily Event

To send daily event, you need to send ICS file. This file looks like that:

cal_day_event.png

I have made a simple UI using an Ajaxtoolkit CalendarExtender. Here, the user can select a different date from calendar and in case of day event creation, there is no need to time.

day_event.png

Here is the code to create day event.

public string MakeDayEvent
	(string subject, string location, DateTime startDate, DateTime endDate)
   {
    string filePath = string.Empty;
    string path = HttpContext.Current.Server.MapPath(@"\iCal\");
    filePath = path + subject + ".ics";
    writer = new StreamWriter(filePath);
    writer.WriteLine("BEGIN:VCALENDAR");
    writer.WriteLine("VERSION:2.0");
    writer.WriteLine("PRODID:-//hacksw/handcal//NONSGML v1.0//EN");
    writer.WriteLine("BEGIN:VEVENT");
    string startDay = "VALUE=DATE:" + GetFormatedDate(startDate);
    string endDay = "VALUE=DATE:" + GetFormatedDate(endDate);
    writer.WriteLine("DTSTART;" + startDay);
    writer.WriteLine("DTEND;" + endDay);
    writer.WriteLine("SUMMARY:" + subject);
    writer.WriteLine("LOCATION:" + location);
    writer.WriteLine("END:VEVENT");
    writer.WriteLine("END:VCALENDAR");
    writer.Close();
    return filePath;        
   }

The code to send mail with attachment is as follows:

public void SendMail(string from, string to, 
	string subject, string body, Attachment attachment)
   {
    MailMessage mail = new MailMessage(from, to, subject, body);
    mail.Attachments.Add(attachment);
    SmtpClient smtp = new SmtpClient("localhost");
    smtp.Send(mail);
    mail.Dispose();
   }

The complete code of that tool is available in the code folder. Please download and try with that.

History

  • Version-1 of that small tool

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ashrafur Rahaman

Software Developer (Senior)

Canada Canada

Member

Software engineer with broad experience in enterprise application development, product deployment automation, software test & test automation, application & system management, and manage big projects and team using proven agile technologies.
 
Passionate on Microsoft technologies, developed solutions using asp.net (1.1/2.0/3.5/4), SQL Server (2005/2008), Sharepoint, Powershell, SSRS, SSAS, WPF, Silverlight, Ajax and so on.
 
Develop innovative application with cutting edge technologies always boosting inside.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow to send this remainder automatically into gmail calender Pinmembervijay.vangaveti118:53 12 Feb '12  
QuestionThanks Million Pinmemberbellay10:15 18 Jun '11  
GeneralFailed to Map path PinmemberHaridass3:19 28 May '11  
GeneralAppointment with color background depending on condition Pinmembersonashish6:00 9 Dec '09  
Answerthis is other way send the appointment without attach it PinmemberAhmed Abu Dagga19:05 20 May '09  
GeneralFailed to map the path '/iCal/'. Pinmemberabhinash.b20:24 25 Sep '08  
QuestionHow to embade it in mail? PinmemberDanko Greiner22:50 9 Sep '08  
Generalproblem with \iCal\ PinmemberMember 26213926:09 1 Sep '08  
GeneralRe: problem with \iCal\ PinmemberHaridass20:04 27 May '11  
GeneralFailed to map the path '/iCal/'. PinmemberMember 26213926:06 1 Sep '08  
GeneralAjax Problem Pinmemberdanielle661023:13 11 Jun '08  
GeneralRe: Ajax Problem Pinmemberdanielle661023:39 11 Jun '08  
GeneralRe: Ajax Problem PinmemberAshrafur Rahaman23:50 11 Jun '08  
Generalthanks! PinmemberRochelle Velasquez-Macazo15:06 29 Apr '08  
GeneralRe: thanks! PinmemberAshrafur Rahaman20:38 29 Apr '08  
thank you too to use my codes.
 
Ashrafur Rahaman

GeneralVery Nice PinmemberBGaddis3:03 1 Apr '08  
GeneralRe: Very Nice PinmemberAshrafur Rahaman4:55 1 Apr '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120529.1 | Last Updated 31 Mar 2008
Article Copyright 2008 by Ashrafur Rahaman
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid