Working with PST Password Protection Properties

Working with PST Password Protection Properties

Microsoft Outlook lets users password protect PST files to restrict access to them. Aspose.Email can detect password protection on a PST file. The password protection is actually only implemented in Outlook; the data are not encrypted at all. And it makes it possible to use the API to extract emails without knowing the password.

Read Password Protected PST Files

You can read password-protected files just like regular unprotected pst files.

using var pst = PersonalStorage.FromFile(fileName);
foreach (var folder in pst.RootFolder.GetSubFolders())
    foreach (var msg in folder.EnumerateMessages())


Check if PST file is Password Protected

The API provides the PersonalStorage.Store.IsPasswordProtected property. The PersonalStorage.Store.IsPasswordProtected property returns true if the PST file is password protected and false if it is not.

The following code snippet demonstrates the use of PersonalStorage.Store.IsPasswordProtected property.

using var pst = PersonalStorage.FromFile("passwordprotectedPST.pst");
Console.WriteLine($"The storage is password protected - {pst.Store.IsPasswordProtected}");

Validate Password in Password Protected PST

The PersonalStorage.Store.IsPasswordValid() method takes the string password as a parameter and returns true if the password is correct and false if it is incorrect.

The following code snippet demonstrates the use of PersonalStorage.Store.IsPasswordValid() method.

using var pst = PersonalStorage.FromFile("passwordprotectedPST.pst");
Console.WriteLine($"Password is valid - {pst.Store.IsPasswordValid("Password1")}");

Adding/Changing/Removing Password on PST Files

The PersonalStorage.Store.ChangePassword method is used to add, change or delete a password.

To do this, follow these steps:

  • Load PST from a file or a stream.
  • Call the PersonalStorage.Store.ChangePassword method. To add or change the password, pass a password string as a parameter, and to remove the password, pass null value.
using var pst = PersonalStorage.Create("SetPasswordOnPST_out.pst", FileFormatVersion.Unicode);
// Add or change the password
const string password = "Password1";
// Remove the password