Extract the email from note.emlx in the zip. Attachments Apple Mail saved as separate files aren’t included.
dotnet add package RecursiveAI.OneMailRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneMail.Sources; using RecursiveAI.OneMail.Stores; using RecursiveAI.OneMail.Stores.Emlx; using var src = FileSource.Open("note.emlx"); var part = EmlxReader.Read(src); if (part.Defects != StoreDefects.None) throw new InvalidDataException( "Bad EMLX."); using var eml = EmlxReader.OpenMessage(src, part); using var dst = File.Create("note.eml"); eml.CopyTo(dst);
Unzip the example, then dotnet run.
Writes or replaces note.eml with the embedded message only.
The full program
The fictional note.emlx contains the following text. The count line ends with LF; the message lines use CRLF. The 207 counts only the message bytes, including the two UTF-8 bytes for é, not the count line or the XML property list.
207 From: Ada <ada@example.test> Date: Thu, 19 Nov 2026 09:00:00 +0000 Subject: Station cafe MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Meet at the café. <?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"><dict><key>flags</key><integer>1</integer></dict></plist>
The program copies the message bytes as they are, then parses the saved EML to check the subject and compares the output with the expected UTF-8 bytes.
using System.Text; using RecursiveAI.OneMail; using RecursiveAI.OneMail.Sources; using RecursiveAI.OneMail.Stores; using RecursiveAI.OneMail.Stores.Emlx; using var file = FileSource.Open("note.emlx"); var entry = EmlxReader.Read(file); if (entry.Defects != StoreDefects.None) throw new InvalidDataException($"Cannot extract message: {entry.Defects}"); using (var message = EmlxReader.OpenMessage(file, entry)) using (var output = File.Create("note.eml")) message.CopyTo(output); var eml = File.ReadAllBytes("note.eml"); var subject = Mail.Parse(eml).Subject; const string expected = "From: Ada <ada@example.test>\r\n" + "Date: Thu, 19 Nov 2026 09:00:00 +0000\r\n" + "Subject: Station cafe\r\nMIME-Version: 1.0\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Transfer-Encoding: 8bit\r\n\r\nMeet at the café.\r\n"; if (!eml.AsSpan().SequenceEqual(Encoding.UTF8.GetBytes(expected)) || subject != "Station cafe") throw new InvalidDataException("The extracted message differs from the input message."); Console.WriteLine($"Subject: {subject}"); Console.WriteLine($"Wrote note.eml: {eml.Length} bytes.");
dotnet run prints:
Subject: Station cafe Wrote note.eml: 207 bytes.
If the count line is invalid or the message is truncated, the reader marks a defect. The example rejects it before creating the EML.
Variations
Read the Apple Mail flags without putting them in the EML. Add these lines after checking entry.Defects in the full program.
// After reading entry, with file still open: var metadata = EmlxReader.ReadMetadata(file, entry); Console.WriteLine($"Apple Mail flags: {metadata.Flags}");
Apple Mail flags: 1Related recipes
Parse an EML file · Extract attachments from email
The short answer
Read the file with EmlxReader.Read, check the returned Defects, and copy the stream from EmlxReader.OpenMessage into an .eml file. That stream includes the embedded email’s headers and body but not Apple Mail’s metadata. Keep the .emlx source open until the copy finishes.
What is EMLX format?
An Apple Mail EMLX file has three parts: a decimal byte-count line, the stated number of message bytes, and usually an XML property list (plist). The plist may record a flag word, dates, and other state that isn’t stored as part of the email. The Library of Congress format description describes the container; OneMail’s EMLX docs explain the ranges it returns.
An EML, by contrast, contains the message without those outer parts. The sample’s note.eml starts with From:, not 207, and ends with the body, not the plist. Renaming the original file wouldn’t remove either extra part.
How do I convert an Apple Mail email to EML without changing its bytes?
Use the count in the file, not a character count or an XML search. The sample’s café demonstrates why those differ: the é takes two bytes in UTF-8. Copying the byte range also means you don’t have to decode and re-encode MIME bodies to get the EML. The full program compares all 207 output bytes and checks the subject separately; a subject can parse correctly even if a bad conversion also includes an unwanted trailer.
EmlxReader.Read reports a bad count line as BadByteCount, with no message range. If the count is larger than the remaining file, it reports TruncatedMessage and cuts the range at the file end. Neither case is a clean conversion. The check in the snippet at the top prevents an empty or cut-off export from being written as though it were complete.
A .partial.emlx may refer to attachments Apple Mail stored separately. The conversion copies only the message bytes present in the input; it does not look up or reattach those files. Keep the original if you need the Apple Mail metadata too. The flags variation reads that metadata separately while leaving it out of the EML.