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