cancel
Showing results for 
Search instead for 
Did you mean: 

Closing Outlook cleanly

john.hammond
Level 6

Good morning all.

We've run into an issue lately when sending out MI Reports which only happens intermittently, and we're trying to eliminate some of the possibilities that could be causing it. Essentially, an email is generated in the queue during the reporting process, which is sent. However, Outlook is 'killed' once this email is sent, but I'm looking for some way of checking that the Outbox is clear before doing so. I can't seem to find a sufficient action in the VBO (Extended and standard), unless I'm being blind. 

Is there a way of checking before closing Outlook that the outbox is clear? Or a slightly more elegant method of closing Outlook other than killing it (assuming that Outlook natively looks to see if it's in the process of sending emails before essentially terminating the process).

Cheers

4 REPLIES 4

ewilson
Staff
Staff
Hi @john.hammond,

As far as I know there is no action within the Outlook VBO to check the Outbox. It can be done within VBA​ though. You could create a new action on the VBO with a code stage that would look something like this:

Dim app = CreateObject("Outlook.Application")
Dim _nameSpace As Microsoft.Office.Interop.Outlook.NameSpace = app.GetNameSpace("MAPI")
Dim Outlook_Folder_ID as Integer = 4
Dim folder As Folder

If Not String.IsNullOrEmpty(Shared_Mailbox) Then
	Dim recipient = _nameSpace.CreateRecipient(Shared_Mailbox)
    recipient.Resolve()
	If recipient.Resolved Then
		folder = _nameSpace.GetSharedDefaultFolder(recipient, Outlook_Folder_ID)
	Else
		Dim ex1 As New System.Exception(VbCrlf + "Failed to resolve shared mailbox '" + Shared_Mailbox + "'.")
		Throw ex1
	End If
Else
	If Not String.IsNullOrEmpty(Account_Display_Name) Then
		Try
			Dim aa As List(Of Account) = _nameSpace.Accounts.Cast(Of Account).ToList()
			folder  = aa.Where(Function(x) x.DisplayName = Account_Display_Name).FirstOrDefault().DeliveryStore.GetDefaultFolder(Outlook_Folder_ID)
		Catch ex As System.Exception
			Dim ex1 As New System.Exception(VbCrlf + "Failed to retrieve default folder for Account Display Name '" + Account_Display_Name + "'." + VbCrlf + ex.Message)
			Throw ex1
		End Try
	Else
		folder = _nameSpace.GetDefaultFolder(Outlook_Folder_ID)
	End If
End If

Count = folder.Items.Count
​

I'll work with the team to get this functionality added to the official VBO.

Cheers,
Eric

ewilson
Staff
Staff
@john.hammond,

FYI - We've posted an update to the Outlook VBO on the DX. It includes a new action called Get Item Count. You can use this to get the count of items from either the Inbox, Sent Items, or Outbox folders.

NOTE: Be wary of the use of Cached Exchange Mode and/or Synchronization Filters on folders. If you are using either of these features you can see a difference in the total number of items in the local Outlook folder vs. what Exchange says you have.

Cheers,
Eric​

Thanks Eric for the update, this new action would be useful in many other scenarios.

robinkyle
Level 2

Summary: System upgrades, abrupt Outlook application shutdown, oversized data files are some of the common reasons which may cause Outlook error: “Outlook PST was not cleanly closed by the last program that used it.” And the outcome is that the user is unable to access the Outlook profile in Microsoft Outlook 2019, 2016, 2013, 2010, 2007, 2003 and earlier versions. Here you can find the solution to resolve this error quickly:

For Microsoft Outlook to run uninterruptedly, it is essential to perform proper maintenance and monitor the size of Outlook PST files, because even minor faults may cause an Outlook profile to become inaccessible. And once the user is stuck, there is only one way to resolve the issue – repair the outlook PST file. 

The following reasons may cause the error: Outlook PST was not cleanly closed by the last program that used it:

  • Abrupt System Shutdown: The system shuts down abruptly either due to power failure or forced system closure even before the end of all applications (Microsoft Outlook).
  • Installation of External software: External software or third-party tools try to plug extra add-ins in the Outlook profile to enhance the user experience. These additional add-ins can become a significant cause of Outlook error.
  • Corruption in Outlook Data Files: Corruption in PST file may lead to Microsoft Outlook crash.
  • Virus or malicious software attack: Any virus or malicious software attack renders the Outlook profile inaccessible.

Resolve the error: ‘Outlook PST was not cleanly closed by the last program that used it.’

Method 1: Archive, clean or compact large PST data:

  • Archiving the mailbox items (including data from all folders) reduces the size of the PST file, which may help in resolving the error.
  • You can also cleanup your Inbox and organize your emails by using the various tools on command bar to ‘Sweep’, ‘Archive’ and ‘Move-to’.
  • Compacting the PST file and using Inbox rules also helps in resolving the Outlook error. Compact the current PST file and save the compacted file at an alternate location.

Note: Microsoft Outlook runs ‘Sweep Rules’ once in a day, and the ‘Inbox Rules’ are applied as soon as an email arrives in the mailbox.

Method 2: Repair PST by using Scanpst.exe:

Note: Scanpst.exe may result in data loss hence, take a backup of PST file before starting with the manual repair process.

  1. Close Microsoft Outlook and start the Scanpst.exe. Check the Outlook version and Windows OS version to locate the inbuilt utility, as different versions have different locations. It may be difficult to locate the Inbox repair tool without knowing the specific Windows OS and Outlook versions.
  2. Browse for the PST file to be repaired. All PST files are available with .pst extension
  3. Click the Options button and provide the Scan Log option
  4. Click the Start button. If the utility detects an error, then the file prompts to start the repair process.
  5. Click  button, and the Outlook utility will start the PST repair process

Scanpst.exe may not always be effective in resolving ‘Outlook PST was not cleanly closed by the last program that used it’ error, due to limitations like:

  • Cannot repair PST files that are more than 2 GB in size
  • Unable to repair PST file with severe corruption
  • Sometimes may result in data loss during the repair process

An Outlook Recovery software like Stellar Repair for Outlook can help overcome these shortcomings of scanpst.exe and provide a more efficient solution in case an Outlook PST was not cleanly closed and gets corrupted.

Method 3: Microsoft Outlook Repair Software

Outlook repair software selects the PST file and repairs the corrupt elements. You can save the corrected data as a new PST to reduce further chances of corruption.
_________________________________________

SF Relationship Coaching & Psychotherapy