Click here to Skip to main content
15,123,851 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
I'm sending a meeting request using the [SMTPClient] class with the VCalendar format.

However, I'm facing the following issues:
- The meeting request is not sent to the organizer.
- The meeting request request is received as an attachment to a plain mail.
- When opened and accepted by the attendee, no reply is sent to the organizer.

Below is the VCalendar format that I'm using:

public static MailMessage CreateMeetingRequestToAll(DateTime dtStart, DateTime dtEnd, string strSubject, string strSummary,
                                        string strLocation, string strOrganizerName, string strOrganizerEmail, MailAddressCollection reqAttendeeList, string UID, SPListItem item, string domainName, bool isToOrganizer)
        {

            //Create an instance of mail message
            MailMessage mmMessage = new MailMessage();
            //  Set up the different mime types contained in the message
            System.Net.Mime.ContentType typeText = new System.Net.Mime.ContentType("text/plain");
            System.Net.Mime.ContentType typeHTML = new System.Net.Mime.ContentType("text/html");
            System.Net.Mime.ContentType typeCalendar = new System.Net.Mime.ContentType("text/calendar");

            //  Add parameters to the calendar header
            typeCalendar.Parameters.Add("Content-class", "urn:content-classes:calendarmessage");
            typeCalendar.Parameters.Add("Content-Type", "text/calendar");
            typeCalendar.Parameters.Add("method", "REQUEST");
            typeCalendar.Parameters.Add("name", "meeting.ics");
            typeCalendar.Parameters.Add("Content-Transfer-Encoding", "8bit");

            //  Create message body parts in text format
            string strBodyText = "Type:Single Meeting\r\nOrganizer: {0}\r\nStart Time:{1}\r\nEnd Time:{2}\r\nTime Zone:{3}\r\nLocation: {4}\r\n\r\n*~*~*~*~*~*~*~*~*~*\r\n\r\n{5}";
            strBodyText = string.Format(strBodyText, strOrganizerName, dtStart.ToLongDateString() + " " + dtStart.ToLongTimeString(),
                                dtEnd.ToLongDateString() + " " + dtEnd.ToLongTimeString(), System.TimeZone.CurrentTimeZone.StandardName,
                                strLocation, strSummary);
            AlternateView viewText = AlternateView.CreateAlternateViewFromString(strBodyText, typeText);
            mmMessage.AlternateViews.Add(viewText);

            //Create the Body in HTML format
            string strBodyHTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<HTML>\r\n<HEAD>\r\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\r\n<META NAME=\"Generator\" CONTENT=\"MS Exchange Server version 6.5.7652.24\">\r\n<TITLE>{0}</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<!-- Converted from text/plain format -->\r\n<P><FONT SIZE=2>Type:Single Meeting<BR>\r\nOrganizer:{1}<BR>\r\nStart Time:{2}<BR>\r\nEnd Time:{3}<BR>\r\nTime Zone:{4}<BR>\r\nLocation:{5}<BR>\r\n<BR>\r\n*~*~*~*~*~*~*~*~*~*<BR>\r\n<BR>\r\n{6}<BR>\r\n</FONT>\r\n</P>\r\n\r\n</BODY>\r\n</HTML>";
            strBodyHTML = string.Format(strBodyHTML, strSummary, strOrganizerName, dtStart.ToLongDateString() + " " + dtStart.ToLongTimeString(),
                                    dtEnd.ToLongDateString() + " " + dtEnd.ToLongTimeString(), System.TimeZone.CurrentTimeZone.StandardName,
                                    strLocation, strSummary);
            AlternateView viewHTML = AlternateView.CreateAlternateViewFromString(strBodyHTML, typeHTML);
            mmMessage.AlternateViews.Add(viewHTML);

            //Create the Body in VCALENDAR format
            string strCalDateFormat = "yyyyMMddTHHmmssZ";

            StringBuilder strBodyCalendar = new StringBuilder();
            strBodyCalendar.AppendLine("BEGIN:VCALENDAR");
            strBodyCalendar.AppendLine("PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN");
            strBodyCalendar.AppendLine("VERSION:2.0");
            strBodyCalendar.AppendLine("METHOD:REQUEST");
            strBodyCalendar.AppendLine("BEGIN:VEVENT");

	    foreach (MailAddress attendee in reqAttendeeList)
            {
               mmMessage.To.Add(attendee);
               strBodyCalendar.AppendFormat("ATTENDEE;CN={0};ROLE=REQ-PARTICIPANT;EXPECT=REQUIRE;RSVP=TRUE:MAILTO:{1}\r\n", attendee.DisplayName, attendee.Address);
            }

            strBodyCalendar.AppendFormat("ORGANIZER:MAILTO:{0}\r\n", strOrganizerEmail);
            strBodyCalendar.AppendFormat("DTSTART:{0}\r\n", dtStart.ToUniversalTime().ToString(strCalDateFormat));
            strBodyCalendar.AppendFormat("DTEND:{0}\r\n", dtEnd.ToUniversalTime().ToString(strCalDateFormat));
            strBodyCalendar.AppendFormat("LOCATION:{0}\r\n", strLocation);
            strBodyCalendar.AppendFormat("TRANSP:OPAQUE\r\n");
            strBodyCalendar.AppendFormat("SEQUENCE:0\r\n");
            strBodyCalendar.AppendFormat("UID:{0}\r\n", UID);
            strBodyCalendar.AppendFormat("DTSTAMP:{0}\r\n", DateTime.Now.ToUniversalTime().ToString(strCalDateFormat));
            strBodyCalendar.AppendFormat("DESCRIPTION:{0}\r\n", strSummary);
            strBodyCalendar.AppendFormat("SUMMARY:{0}\r\n", strSubject);
            strBodyCalendar.AppendLine("PRIORITY:5");
            strBodyCalendar.AppendLine("X-MICROSOFT-CDO-IMPORTANCE:1");
            strBodyCalendar.AppendLine("CLASS:PUBLIC");
            strBodyCalendar.AppendLine("BEGIN:VALARM");
            strBodyCalendar.AppendLine("TRIGGER:-PT15M");
            strBodyCalendar.AppendLine("ACTION:DISPLAY");
            strBodyCalendar.AppendLine("DESCRIPTION:Reminder");
            strBodyCalendar.AppendLine("END:VALARM");
            strBodyCalendar.AppendLine("END:VEVENT");
            strBodyCalendar.AppendLine("END:VCALENDAR");

            AlternateView viewCalendar = AlternateView.CreateAlternateViewFromString(strBodyCalendar.ToString(), typeCalendar);
            //viewCalendar.TransferEncoding = TransferEncoding.SevenBit;
            mmMessage.AlternateViews.Add(viewCalendar);

            //Adress the message
            mmMessage.From = new MailAddress(strOrganizerEmail);            
            mmMessage.Subject = strSubject;
            FillAttachmentCollection(ref mmMessage, item);
            return mmMessage;
        }
Posted
Updated 7-Mar-11 3:17am
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900