Recursive AI

Convert ICS to Outlook MSG in C#

OneMail is a free, open-source email library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

event.ics in the download becomes a standalone Outlook appointment.

Terminal
dotnet add package RecursiveAI.OneMail

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneMail.Calendar;
using RecursiveAI.OneMail.Calendar.Ics;
using RecursiveAI.OneMail.Conversion.OxcIcal;
using RecursiveAI.OneMail.Msg;
 
var doc = ContentDocument.Parse(
    File.ReadAllBytes("event.ics"));
var calendar = IcsDocument.Calendars(doc)
    .First();
var converter = new IcsToMapiConverter();
var item = converter.Convert(calendar);
foreach (var loss in item.Report)
    Console.WriteLine(loss.Code);
MsgWriter.Write(item.Value, "event.msg");
Console.WriteLine("Wrote event.msg");

Unzip the example, then dotnet run.

The snippet writes event.msg and reports two approximations:

Text
FloatingTimeAssumedUtc
DtstampAsLastModified
Wrote event.msg

FloatingTimeAssumedUtc means OneMail used UTC because the event times had no time zone; DtstampAsLastModified means it used DTSTAMP as the last-modified time.

The full program

event.ics is in the download:

Text
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example//Studio calendar//EN
BEGIN:VEVENT
UID:review@example.test
DTSTAMP:20261130T120000Z
DTSTART:20261201T140000
DTEND:20261201T143000
SUMMARY:Studio review
LOCATION:Room 2
END:VEVENT
END:VCALENDAR
C#
using RecursiveAI.OneMail.Calendar;
using RecursiveAI.OneMail.Calendar.Ics;
using RecursiveAI.OneMail.Conversion.OxcIcal;
using RecursiveAI.OneMail.Msg;
 
var doc = ContentDocument.Parse(
    File.ReadAllBytes("event.ics"));
var calendar = IcsDocument.Calendars(doc).First();
var item = new IcsToMapiConverter().Convert(calendar);
foreach (var loss in item.Report)
    Console.WriteLine(loss.Code);
MsgWriter.Write(item.Value, "event.msg");
Console.WriteLine("Wrote event.msg");
if (!MsgFile.TryOpen("event.msg", out var saved, out _))
    throw new InvalidDataException("Could not read event.msg");
using (saved)
{
    Console.WriteLine($"Class: {saved.Message.MessageClass}");
    Console.WriteLine($"Subject: {saved.Message.Subject}");
}

dotnet run prints:

Text
FloatingTimeAssumedUtc
DtstampAsLastModified
Wrote event.msg
Class: IPM.Appointment
Subject: Studio review

The full program opens the saved file and reads back its message class and subject.

If the calendar has neither a VEVENT (event) nor a VTODO (task), the converter returns an empty appointment with NoEventOrTask in the report. Check that the file contains the event you meant to export before saving.

Variations

Get the MSG as bytes. Replace the last two lines of the snippet with these to keep the file in memory:

C#
byte[] msgBytes = MsgWriter.ToArray(item.Value);
Console.WriteLine($"MSG bytes available: {msgBytes.Length > 0}");

The sample still reports the same two approximations, then prints:

Text
MSG bytes available: True

The short answer

Parse the .ics file, take its VCALENDAR, and pass it to IcsToMapiConverter. The result holds an Outlook item in memory and a report of what changed or was left out. Pass item.Value to MsgWriter.Write to save the item as .msg; inspect item.Report first if the exact time or recurrence matters. You don’t need Outlook to produce the file.

How do I import an ICS event into Outlook?

If the goal is just to add the event to your own calendar, skip MSG conversion. Outlook on the web can upload an .ics file directly. Under Add calendar, choose Upload from file, pick the ICS file and choose the destination calendar. That’s an import into a calendar, not a way to generate an .msg attachment. Use the C# example when you need the standalone Outlook item for another step in your application.

What happens to the event time and recurrence in an ICS-to-MSG conversion?

The sample time 20261201T140000 has neither Z nor a TZID parameter. If you meant 2 p.m. local time in a specific zone, don’t rely on the UTC assumption. Supply an explicit UTC instant (Z) or a resolvable TZID. OneMail can also use the calendar’s VTIMEZONE definition, which carries the rules for that zone. An unknown zone falls back to UTC with UnknownTimeZone in the report.

A recurring event isn’t exported as one file per date. When the rule fits Outlook’s recurrence representation, the item holds the series. Occurrences moved or edited in the source can become exception attachments within that item; a rule with no Outlook equivalent produces RecurrenceNotMapped. Read the calendar conversion notes before relying on the output to represent every instance.

For a file with several separate events, Convert returns the first item and reports AdditionalItemsNotConverted. ConvertAll returns one result per event series or task in a VCALENDAR. Use a different output name for each result and check each report separately. The METHOD on the calendar also matters: without one, as in this example, the class is IPM.Appointment; REQUEST represents a meeting request instead.

All onemail recipes