---
title: "Convert a VCF to an Outlook contact MSG in C#"
url: https://recursiveai.org/onemail/cookbook/convert-vcard-to-outlook-contact-msg/
description: "Convert a vCard (VCF) to an Outlook contact MSG file in C# with OneMail, and read the conversion report to find values that didn’t fit."
version: "1.0.1"
---

Read the zip’s `contact.vcf` and write it as an Outlook contact `.msg`. The converter also lists any vCard values that didn’t fit. Outlook doesn’t need to be installed.

```shell
dotnet add package RecursiveAI.OneMail
dotnet add package RecursiveAI.OneMail.Calendar
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneMail.Calendar;
using RecursiveAI.OneMail.Calendar.VCard;
using RecursiveAI.OneMail.Conversion.OxVCard;
using RecursiveAI.OneMail.Msg;

var bytes = File.ReadAllBytes("contact.vcf");
var doc = ContentDocument.Parse(bytes);
var card = VCardDocument.Cards(doc).Single();
var result = new VCardToContactConverter()
    .Convert(card.Component);
File.WriteAllBytes("contact.msg",
    MsgWriter.ToArray(result.Value));
Console.WriteLine("Wrote contact.msg");
foreach (var loss in result.Report)
    if (loss.IsContentLoss)
        Console.WriteLine($"{loss.Name}: {loss.Code}");
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onemail/cookbook/convert-vcard-to-outlook-contact-msg/convert-vcard-to-outlook-contact-msg.zip) and `dotnet run`.

```text
Wrote contact.msg
EMAIL: AdditionalValueNotMapped
```



The zip’s `contact.vcf` is a synthetic vCard with four email addresses:

```text
BEGIN:VCARD
VERSION:3.0
FN:Morgan Lee
N:Lee;Morgan;;;
EMAIL:morgan@example.com
EMAIL:mlee@example.org
EMAIL:ml@example.net
EMAIL:fourth@example.com
END:VCARD
```

This example expects exactly one card. `Single()` throws `InvalidOperationException` if the file contains none or more than one.

## Variations

**Require no content loss.** To reject a card rather than write a contact missing some values, add this check before writing the file:

```csharp
if (result.Report.HasContentLoss)
    throw new InvalidDataException(
        "Some vCard values did not carry over.");
```

## Related recipes

- [Convert an Outlook contact to vCard](https://recursiveai.org/onemail/cookbook/convert-outlook-contact-to-vcard/) for the reverse conversion.
- [Convert vCard to jCard or xCard](https://recursiveai.org/onemail/cookbook/convert-vcard-to-jcard-and-xcard/) to keep the vCard model in JSON or XML.

## The short answer

Parse the `.vcf` with `ContentDocument`, then pass the card’s component to `VCardToContactConverter`. Write `result.Value` with `MsgWriter` and read `result.Report` for fields that were dropped or approximated. The file is an `IPM.Contact` Outlook item, not an email message, and the conversion does not require Outlook to be installed.

## How do I import a VCF contact into Outlook?

If your goal is to add a card to your address book by hand, [Microsoft’s Outlook instructions](https://support.microsoft.com/en-au/office/import-vcards-to-outlook-contacts-70c6b31f-19f8-4033-8f2a-2ee8075e51aa) cover opening or saving a vCard directly. Use the C# conversion when your application needs to produce a standalone `.msg` contact file rather than add a contact to a user’s address book. The example writes a local file; it doesn’t connect to a mailbox or insert the contact into a Contacts folder.

## What if a VCF file contains multiple contacts?

`VCardDocument.Cards` enumerates the vCards in the document. This example uses `Single()` so that a file with multiple contacts can’t silently become an MSG with just the first contact. For a batch export, iterate the cards and convert each component to its own numbered `.msg`, pairing each report with the file it describes.

## Which vCard fields carry over to an Outlook contact?

The [contact mapping](https://recursiveai.org/onemail/docs/contacts/#vcard-to-contact-vcardtocontactconverter) assigns values to specific Outlook properties. The first three email addresses go into separate email slots; the fourth is reported as `AdditionalValueNotMapped`. Some values don’t fit for other reasons: a birthday without a year is reported as `PartialDate`, and a photo given only as a URI is reported as `PhotoNotInline`. The converter also records bookkeeping such as the vCard version. Filtering on `IsContentLoss` keeps those bookkeeping entries separate from values that changed or didn’t make it into the file.
