Created
September 26, 2025 15:32
-
-
Save aspose-com-gists/bac69d1a5a8eda883cfc3a41d2e2a308 to your computer and use it in GitHub Desktop.
Extract Properties, Attachments, and Recipients from PST Files in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the PST file | |
using (var pst = PersonalStorage.FromFile("sample.pst")) | |
{ | |
// Specify the EntryId of the target message | |
var targetEntryId = "..."; // Your message's EntryId here | |
// Extract the attachments collection for this message | |
var attachments = pst.ExtractAttachments(targetEntryId); | |
// Check if any attachments exist | |
if (attachments.Any()) | |
{ | |
Console.WriteLine($"Found {attachments.Count} attachment(s). Saving..."); | |
// Save each attachment to disk | |
foreach (var attachment in attachments) | |
{ | |
var filePath = Path.Combine("OutputDir", attachment.FileName); | |
attachment.Save(filePath); | |
Console.WriteLine("Saved: " + filePath); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("No attachments found for this message."); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the PST file | |
using (var pst = PersonalStorage.FromFile("sample.pst")) | |
{ | |
// Specify the EntryId of the target message | |
var targetEntryId = "..."; // Your message's EntryId here | |
// Extract the recipients collection for this message | |
var recipients = pst.ExtractRecipients(targetEntryId); | |
// Check if any recipients exist | |
if (recipients.Any()) | |
{ | |
Console.WriteLine("Recipients:"); | |
// Display details for each recipient | |
foreach (var recipient in recipients) | |
{ | |
Console.WriteLine($"\tName: {recipient.DisplayName}"); | |
Console.WriteLine($"\tEmail: {recipient.EmailAddress}"); | |
Console.WriteLine($"\tType: {recipient.RecipientType}"); // To, Cc, Bcc | |
Console.WriteLine("\t---"); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("No recipients found for this message."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment