Send appointment through mail in asp.net

No.of Views1423
Bookmarked0 times
Downloads 
Votes0
By  ashraf   On  16 Feb 2010 03:02:44
Tag : ASP.NET , How to
Send appointment or event through mail, so it can be synchronized it with outlook calendar
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Now a day’s 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 event both hour event and day event. This concept is very simple creating a ics file and sending as mail attachment.

Image Loading

Implementation

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

Send Event/Appointment

In outlook two type of event/appointment 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 need to send ics file for hour event ics file look like that

Image Loading

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

Image Loading

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 need to send ics file this file look like that

Image Loading

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

Image Loading

Here are the codes 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;
}

Code to send mail with attachement

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();
}

Conclusion

In this article i have given detail to send appointment through the email in ASP.NET. thank yo for reading.

Sample Project Source

Download source files -780 kb

 
Sign Up to vote for this article
 
About Author
 
ashraf
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-01 Aug 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top