Could not find .ics file inside mail in mailbox

Hello Supporter.
We are implementing a ics importer using aspose.mail.

We have a mailbox for example. When a invitation is sent to the mailbox, then we could read ics file in the email by using code:

if (_message.AlternateViews.Count > 0)
{
    int num = 1;
    foreach (AlternateView alternateView in _message.AlternateViews)
    {
         if (alternateView.ContentType.MediaType == "text/calendar")
        {
            string text = new StreamReader(alternateView.ContentStream).ReadToEnd();
            //parse file and do something
        }

      num++;
}

BUT if I use mails from outlook 365 to send invitations and receive invitations, then I could not find .ics file inside mails.
Then I tried to save the mail to a folder in eml format,then I could see ics file in eml
image.png (23.9 KB)

Looks like the problem is related to TNEF (Transport Neutral Encapsulation Format)?
Does Aspose.mail support a better way where I could find .ics in all situations?

Thank you very much for your support.
Yours.
Nghia

@nguyen.xuan.nghia

Why the .ics is not found

Your current code looks for a calendar part in the AlternateViews collection, which works for messages that expose the invitation directly as an alternate view (see the examples in the forum [2][3][4]).

You reported that invitations sent from Outlook 365 do not contain such an alternate view. In many cases Outlook wraps the calendar data in a TNEF (winmail.dat) attachment, so the .ics file is no longer present in AlternateViews.

How to handle the situation

  1. Keep the existing logic – it will still find the calendar when it is present as an alternate view.

  2. Check the Attachments collection – when the message is TNEF‑encapsulated, the calendar may appear as a regular attachment (often with a .ics name or a text/calendar content type). You can iterate through msg.Attachments and look for an attachment whose name ends with “.ics” or whose ContentType.MediaType is "text/calendar".

  3. If a TNEF part is present – Outlook‑generated messages may contain a TNEF block (winmail.dat). Aspose.Email can expose this block, allowing you to enumerate its inner attachments and locate the calendar file.

By combining the check of AlternateViews with a scan of Attachments (and, when needed, the TNEF block), you should be able to retrieve the .ics data regardless of whether the message is plain or TNEF‑wrapped.

Hi Supporter.
Thank you very much for your support. BUT I could not see any attachment.

I tried to test like this:
Here is my code:

Logging.LogInfo(info, "Loading emails without using LoadOptions");
MailMessage messageNoOptions = MailMessage.Load(streamMimeMessage);
messageNoOptions.Save("output.eml",SaveOptions.DefaultEml);
Logging.LogInfo(info, $"message.OriginalIsTnef: {messageNoOptions.OriginalIsTnef}");
var appointmentHandlerNoOptions = new AppointmentHandler(messageNoOptions, info, currentMemberId, dateTimeRunApp, mimeMessage.Date.DateTime);

And I see that there is no attachment.
Watch the image:
NoAnyAttachment.png (30.5 KB)

Output file : output.eml looks like this:
DetailEmlContent.png (71.2 KB)

And this is body of the mail, It said something related to .icalendar format
Watch:
BodyTextOfMail.png (17.9 KB)

I could not find a way to read text/calendar mine file.
BUT I could see text/calendar mine in output.eml.

Hope you can support me way to get text/calendar mine.

Thank you very much.
Yours.
Nghia

Hello @nguyen.xuan.nghia,

Could you please send us the original EML that was saved from the streamMimeMessage ? This will help us investigate the issue.

Thank you.

Hi supporter.

Here is the eml file which I saved from MimeMessage
outputMimeMessage.zip (4.2 KB)

I used the code to save:

 MimeMessage mimeMessage = inboxMessage.OneUnreadMessage;
 string emlFilePath = "outputMimeMessage.eml";
 using (var fileStream = new FileStream(emlFilePath, FileMode.Create))
 {
     mimeMessage.WriteTo(fileStream);
 }

Thank for your checking and feedback.
Yours.
Nghia

Hello @nguyen.xuan.nghia,

Thank you for providing the original EML file.

After reviewing outputMimeMessage.eml, we can confirm the following:

  1. There is no text/calendar MIME part and no .ics attachment in this email
    The message structure is not multipart and contains only:

    Content-Type: text/html; charset="utf-8"
    

    There are:

    • No attachments
    • No AlternateView with text/calendar
    • No application/ms-tnef content (even though the X-MS-TNEF-Correlator header is present)
  2. This email is not a classic Outlook meeting invitation with iCalendar data
    The message is an HTML notification generated by Outlook / Microsoft Teams.
    The body contains links to Outlook Web / Teams and explicitly states:

    “To receive meeting invitations as .iCalendar attachments instead of Outlook Web App links…”

    This means the sender’s Outlook 365 is configured to send links only, not actual iCalendar (.ics) data.

  3. Outlook can render calendar data dynamically even when:

    • No .ics file is attached
    • No text/calendar MIME part exists

    However, this calendar data is not transmitted via SMTP, so it does not appear in the raw EML and cannot be extracted by any lib.

  4. This is not a TNEF or Aspose.Email issue

    • The provided EML does not contain TNEF (application/ms-tnef)
    • MailMessage.Load() works correctly
    • Attachments and AlternateViews are empty because the corresponding MIME parts do not exist in the source message

    Aspose.Email cannot extract .ics data if it was never included in the email.

Can you change Outlook 365 settings on the sender side? In Outlook on the web (Office 365), invite “format” is mainly controlled by a setting that forces iCalendar (.ics) attachments instead of Outlook Web App links, but this option exists only in some tenants and only for POP/IMAP scenarios.
With this setting enabled, Outlook will send text/calendar MIME parts or .ics attachments.

Also, you may try to handle HTML-based invitations if changing sender settings is not possible.
However, we are not sure if this method will work.

  • Detect Outlook / Teams invitation emails
  • Extract meeting details from the HTML body (meeting link, ID, passcode, etc.)