F
francesco
Dear All,
I developed an application to send meeting invitation using iCAL 2.0
protocol. The code is sent both in a proper body-section with
ContentType("text/calendar") and as attachment (.ics).
Once the receiver opens the email, the emai client evaluates such a
body-section and displays all the data properly as a normal meeting request
(showing the ACCEPT | TENTATIVE | DECLINE buttons).
This works with: Gmail, Thunderbird and Outlook 2003.
In Outlook 2007 the email is received as normal message. Only opening the
..ics attachment it then displays (in the attachment window) the buttons.
How should I edit my code in order to be able to display directly the
buttons in OE2007?
Here the code for creating the iCAL invitation:
string Content = "";
Content += "BEGIN:VCALENDAR\r\n";
Content += "PRODID:Microsoft CDO for Microsoft Exchange\r\n";
Content += "VERSION:2.0\r\n";
Content += "METHOD:REQUEST\r\n";
Content += "BEGIN:VEVENT\r\n";
Content +=
"ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:" +
person.eMail + "\r\n";
Content += "ORGANIZER:MAILTO:" + Organizer.eMail + "\r\n";
Content += "DTSTART:" + this.GetDateTime(this.Start) + "\r\n";
//LOCAL TIME
Content += "DTEND:" + this.GetDateTime(this.End) + "\r\n";
//LOCAL TIME
Content += "LOCATION:" + this.Location + "\r\n";
Content += "DTSTAMP:" + this.GetDateTime(DateTime.Now) + "\r\n";
Content += "UID:" + this.UID + "\r\n";
Content += "CREATED: " + this.GetDateTime(DateTime.Now) +
"\r\n";
Content += "SEQUENCE:0\r\n"; //Keeps track if the iCAL is
modified
Content += "LAST-MODIFIED: " + this.GetDateTime(DateTime.Now) +
"\r\n";
Content += "PRIORITY:5\r\n";
Content += "X-MICROSOFT-CDO-TZID:11\r\n";
Content += "STATUS:CONFIRMED\r\n";
Content += "TRANSP:OPAQUE\r\n";
Content += "DESCRIPTION:" + this.Description.Replace("\r\n",
"\\n") + "\r\n";
Content += "SUMMARY:" + this.Summary + "\r\n";
Content += "X-MICROSOFT-CDO-BUSYSTATUS:BUSY";
Content += "X-MICROSOFT-CDO-IMPORTANCE:1";
Content += "X-MICROSOFT-DISALLOW-COUNTER:TRUE";
Content += "X-MS-OLK-ALLOWEXTERNCHECK:TRUE";
Content += "X-MS-OLK-AUTOFILLLOCATION:TRUE";
Content += "X-MS-OLK-CONFTYPE:0";
Content += "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\r\n";
Content += "BEGIN:VALARM\r\n";
Content += "ACTIONISPLAY\r\n";
Content += "DESCRIPTION:REMINDER\r\n";
Content += "TRIGGERT15M\r\n";
Content += "END:VALARM\r\n";
Content += "END:VEVENT\r\n";
Content += "END:VCALENDAR\r\n";
And here the main part of the class sending the email:
MailMessage message = new MailMessage();
string tempFilePath = "";
string Body = this.CreateBody(ToEMail);
string Subject = this.CreateSubject(ToEMail);
message.Sender = new MailAddress(this.FromEMail, "");
message.From = new MailAddress(this.ReplyEMail, this.FromName);
message.To.Add(new MailAddress(ToEMail));
message.Body = Body;
message.Subject = this.CreateSubject(ToEMail);
message.IsBodyHtml = true;
if (this._Calendar != null)
{
this.Calendar.Description = Body
string attachmentCode = this.Calendar.GetICalendarText();
/*Setting content type */
ContentType calendarType = new ContentType("text/calendar");
calendarType.Parameters.Add("method", "REQUEST");
calendarType.CharSet = "utf-8";
int randNum = new Random().Next(100);
string meetingFileName = "meetingInvitation"+randNum+".ics";
tempFilePath =
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath
+ "/Temp/" + meetingFileName);
if (!string.IsNullOrEmpty(attachmentCode))
{
StreamWriter tw = new StreamWriter(tempFilePath);
tw.WriteLine(attachmentCode);
tw.Dispose();
tw.Close();
if (File.Exists(tempFilePath))
{
/*Creating the attachment*/
Attachment item = new Attachment(tempFilePath,
MediaTypeNames.Application.Octet);
item.TransferEncoding = TransferEncoding.SevenBit;
calendarType.Parameters.Add("name",
""+meetingFileName+"");
ContentDisposition disp = item.ContentDisposition;
disp.CreationDate =
System.IO.File.GetCreationTime(tempFilePath);
disp.ModificationDate =
System.IO.File.GetLastWriteTime(tempFilePath);
disp.DispositionType =
DispositionTypeNames.Attachment;
message.Attachments.Add(item);
}
}
/*Creating the alternative view for the meeting invitation*/
AlternateView calendarView =
AlternateView.CreateAlternateViewFromString(attachmentCode, calendarType);
message.AlternateViews.Add(calendarView);
}
smtp.Send(message);
Thanks in advance for any suggestion.
Regards,
Francesco
I developed an application to send meeting invitation using iCAL 2.0
protocol. The code is sent both in a proper body-section with
ContentType("text/calendar") and as attachment (.ics).
Once the receiver opens the email, the emai client evaluates such a
body-section and displays all the data properly as a normal meeting request
(showing the ACCEPT | TENTATIVE | DECLINE buttons).
This works with: Gmail, Thunderbird and Outlook 2003.
In Outlook 2007 the email is received as normal message. Only opening the
..ics attachment it then displays (in the attachment window) the buttons.
How should I edit my code in order to be able to display directly the
buttons in OE2007?
Here the code for creating the iCAL invitation:
string Content = "";
Content += "BEGIN:VCALENDAR\r\n";
Content += "PRODID:Microsoft CDO for Microsoft Exchange\r\n";
Content += "VERSION:2.0\r\n";
Content += "METHOD:REQUEST\r\n";
Content += "BEGIN:VEVENT\r\n";
Content +=
"ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:" +
person.eMail + "\r\n";
Content += "ORGANIZER:MAILTO:" + Organizer.eMail + "\r\n";
Content += "DTSTART:" + this.GetDateTime(this.Start) + "\r\n";
//LOCAL TIME
Content += "DTEND:" + this.GetDateTime(this.End) + "\r\n";
//LOCAL TIME
Content += "LOCATION:" + this.Location + "\r\n";
Content += "DTSTAMP:" + this.GetDateTime(DateTime.Now) + "\r\n";
Content += "UID:" + this.UID + "\r\n";
Content += "CREATED: " + this.GetDateTime(DateTime.Now) +
"\r\n";
Content += "SEQUENCE:0\r\n"; //Keeps track if the iCAL is
modified
Content += "LAST-MODIFIED: " + this.GetDateTime(DateTime.Now) +
"\r\n";
Content += "PRIORITY:5\r\n";
Content += "X-MICROSOFT-CDO-TZID:11\r\n";
Content += "STATUS:CONFIRMED\r\n";
Content += "TRANSP:OPAQUE\r\n";
Content += "DESCRIPTION:" + this.Description.Replace("\r\n",
"\\n") + "\r\n";
Content += "SUMMARY:" + this.Summary + "\r\n";
Content += "X-MICROSOFT-CDO-BUSYSTATUS:BUSY";
Content += "X-MICROSOFT-CDO-IMPORTANCE:1";
Content += "X-MICROSOFT-DISALLOW-COUNTER:TRUE";
Content += "X-MS-OLK-ALLOWEXTERNCHECK:TRUE";
Content += "X-MS-OLK-AUTOFILLLOCATION:TRUE";
Content += "X-MS-OLK-CONFTYPE:0";
Content += "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\r\n";
Content += "BEGIN:VALARM\r\n";
Content += "ACTIONISPLAY\r\n";
Content += "DESCRIPTION:REMINDER\r\n";
Content += "TRIGGERT15M\r\n";
Content += "END:VALARM\r\n";
Content += "END:VEVENT\r\n";
Content += "END:VCALENDAR\r\n";
And here the main part of the class sending the email:
MailMessage message = new MailMessage();
string tempFilePath = "";
string Body = this.CreateBody(ToEMail);
string Subject = this.CreateSubject(ToEMail);
message.Sender = new MailAddress(this.FromEMail, "");
message.From = new MailAddress(this.ReplyEMail, this.FromName);
message.To.Add(new MailAddress(ToEMail));
message.Body = Body;
message.Subject = this.CreateSubject(ToEMail);
message.IsBodyHtml = true;
if (this._Calendar != null)
{
this.Calendar.Description = Body
string attachmentCode = this.Calendar.GetICalendarText();
/*Setting content type */
ContentType calendarType = new ContentType("text/calendar");
calendarType.Parameters.Add("method", "REQUEST");
calendarType.CharSet = "utf-8";
int randNum = new Random().Next(100);
string meetingFileName = "meetingInvitation"+randNum+".ics";
tempFilePath =
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath
+ "/Temp/" + meetingFileName);
if (!string.IsNullOrEmpty(attachmentCode))
{
StreamWriter tw = new StreamWriter(tempFilePath);
tw.WriteLine(attachmentCode);
tw.Dispose();
tw.Close();
if (File.Exists(tempFilePath))
{
/*Creating the attachment*/
Attachment item = new Attachment(tempFilePath,
MediaTypeNames.Application.Octet);
item.TransferEncoding = TransferEncoding.SevenBit;
calendarType.Parameters.Add("name",
""+meetingFileName+"");
ContentDisposition disp = item.ContentDisposition;
disp.CreationDate =
System.IO.File.GetCreationTime(tempFilePath);
disp.ModificationDate =
System.IO.File.GetLastWriteTime(tempFilePath);
disp.DispositionType =
DispositionTypeNames.Attachment;
message.Attachments.Add(item);
}
}
/*Creating the alternative view for the meeting invitation*/
AlternateView calendarView =
AlternateView.CreateAlternateViewFromString(attachmentCode, calendarType);
message.AlternateViews.Add(calendarView);
}
smtp.Send(message);
Thanks in advance for any suggestion.
Regards,
Francesco