Install MSGReader via NuGet
masterThe easiest way to install MSGReader is via the NuGet package manager. Run the following command in the Visual Studio Package Manager Console:
Install-Package MSGReaderrepository·master·Indexed 19 days ago
https://github.com/sicos1977/msgreaderA .NET assembly for reading Outlook MSG and EML (Mime 1.0) files. It supports Outlook objects including E-mails, Appointments, Tasks, Contacts, and Sticky notes. Features include support for HTML embedded in RTF, charset detection via the UTF.Unknown package, attachment manipulation, and COM visibility for use in VB6 and VBScript.
The easiest way to install MSGReader is via the NuGet package manager. Run the following command in the Visual Studio Package Manager Console:
Install-Package MSGReaderMSGReader can be used in COM-based environments after registering the assembly.
Regasm.exe /codebase MsgReader.dllCreateObject.dim msgreader
set msgreader = createobject("MsgReader.Reader")
msgreader.ExtractToFolderFromCom "the msg file to read", "the folder where to place the extracted files"When MSG files contain HTML encapsulated in RTF, multiple languages might cause encoding issues. MSGReader uses the UTF.Unknown package to detect character encodings. You can adjust the CharsetDetectionEncodingConfidenceLevel property on the Reader or Message class to control the detection threshold.
0.90f0.70f as they likely produce incorrect results.// Set the threshold for encoded string detection
// Default is 0.90f
message.CharsetDetectionEncodingConfidenceLevel = 0.90f;You can manipulate an MSG file by removing attachments. To do this, open the message with FileAccess.ReadWrite, call DeleteAttachment on the specific attachment object, and then call Save to write the changes to a new file.
var outlook = new Storage.Message(fileName, FileAccess.ReadWrite);
outlook.DeleteAttachment(outlook.Attachments[0]);
outlook.Save("d:\\deleted.msg");To read Mime 1.0 (.eml) files, use MsgReader.Mime.Message.Load(FileInfo). You can access headers (including To recipients and Subject) and extract the text or HTML body. Note that body content is returned as byte arrays, so you should decode them using an encoding like System.Text.Encoding.UTF8.
var fileInfo = new FileInfo("d:\\testfile.eml");
var eml = MsgReader.Mime.Message.Load(fileInfo);
if (eml.Headers != null)
{
if (eml.Headers.To != null)
{
foreach (var recipient in eml.Headers.To)
{
var to = recipient.Address;
}
}
}
var subject = eml.Headers.Subject;
if (eml.TextBody != null)
{
var textBody = System.Text.Encoding.UTF8.GetString(eml.TextBody.Body);
}
if (eml.HtmlBody != null)
{
var htmlBody = System.Text.Encoding.UTF8.GetString(eml.HtmlBody.Body);
}
// etc...Use the MsgReader.Outlook.Storage.Message class to load an .msg file and access its properties such as sender, sent date, recipients, subject, and body content. You can retrieve specific recipient lists using GetEmailRecipients with a RecipientType (e.g., To or Cc).
using (var msg = new MsgReader.Outlook.Storage.Message("d:\\testfile.msg"))
{
var from = msg.Sender;
var sentOn = msg.SentOn;
var recipientsTo = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.To, false, false);
var recipientsCc = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.Cc, false, false);
var subject = msg.Subject;
var htmlBody = msg.BodyHtml;
// etc...
}