We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ICS files as attachments in a mail message

We have some ICS files as attachments in GMAIL. When we try to display the mails in our webmail application which we develop through IMAP, we get the ICS content in our mail body as shown below and we are not able to retrieve the appointment and show/download it as ICS for users to accept.

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:REPLY
BEGIN:VEVENT

How do we show the appointment/meeting as an attachment in our webmail using MailMessage.AlternateView? Any help is appreciated. Thanks in advance


After some analysis I have found the code for this. Just thought of sharing this. This code will be helpful if you have an invitation and want to show that in the webmail as an attachment.

foreach (AlternateView aview in mailMsg.AlternateViews)
{
if (aview.ContentType.MediaType == "text/calendar")
{
LinkButton lnkAttachment = new LinkButton();
lnkAttachment.ID = "lnkAttachment" + Count;
lnkAttachment.Text = "Meeting.ics;";
}
}

The above code is to show the meeting.ics as a link.

foreach (AlternateView aview in mailMsg.AlternateViews)
{
if (aview.ContentType.MediaType == "text/calendar")
{
Stream calendarStream = aview.ContentStream;
byte[] buffer = new byte[4096];
using (calendarStream)
{
int Count = 0;
do
{
Count = calendarStream.Read(buffer, 0, buffer.Length); stream.Write(buffer, 0, Count);
}
while (Count != 0);
}
stream.Position = 0;
byte[] fileData = stream.ToArray();
stream.Flush();
stream.Close();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=meeting.ics");
Response.BufferOutput = true;
Response.BinaryWrite(fileData);
Response.End();
}
}

The above code is to download the ics file.