Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active January 18, 2022 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/15d4d3b09aa68953fc2c7106aa764aab to your computer and use it in GitHub Desktop.
Save aspose-com-gists/15d4d3b09aa68953fc2c7106aa764aab to your computer and use it in GitHub Desktop.
Read Outlook MSG Files in C# .NET
// Create an instance of MailMessage from file
MailMessage message = MailMessage.Load("sample.msg");
// Iterate through the attachments collection
foreach (var attachment in message.Attachments)
{
// Save the attachment
attachment.Save(attachment.Name);
}
// Create an instance of MailMessage from file
MailMessage message = MailMessage.Load("sample.msg");
// Get subject
Console.WriteLine("Subject:" + message.Subject);
// Get from address
Console.WriteLine("From:" + message.From);
// Get body
Console.WriteLine("Body" + message.Body);
// Get recipients information
Console.WriteLine("Recipient: " + message.To);
// Get attachments
foreach (var att in message.Attachments)
{
Console.Write("Attachment Name: " + att.Name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment