Some people like to have voicemail forwarded to email, but when they try to listen, the attachment won’t open. That’s because Outlook SecureTempFolder is full. Here’s how to automatically empty it upon closing Outlook.

In Outlook SecureTemp Files Folder and Red X’s in Email Messages I explain what the SecureTemp folder is and issues that result from a “full” SecureTemp folder. I also tell you how to find the folder and empty it manually.

While you can delete the contents of the SecureTempFolder manually, you may want to delete the folder each time you close Outlook.

Source: Clear SecureTempFolder automatically using VBA

TLDR: Here is the script that you add to ThisOutlookSession using the VBA script editor ([Alt]-[F11]):

  1. Option Explicit
  2.  
  3. 'If you prefer to run this manually whenever you feel like it, change Private Sub Application_Quit() to Public Sub EmptySecureTemp() and run it as needed.
  4. Private Sub Application_Quit()
  5. '=====================================================================
  6. ' Deletes the files of the SecureTempFolder (OLK) when closing Outlook
  7. ' (c) Peter Marchert - //www.outlook-stuff.com
  8. ' 2008-11-06 Version 1.0.0
  9. '=====================================================================
  10. Dim objFSO As Object
  11. Dim objWsh As Object
  12. Dim objFolder As Object
  13. Dim strRegKey As String
  14. Dim strOLK As String
  15.  
  16. On Error Resume Next
  17. '---------------------------------------------------------------------
  18. ' To read data from the registry
  19. '---------------------------------------------------------------------
  20.  
  21. Set objWsh = CreateObject("WScript.Shell")
  22.  
  23. '---------------------------------------------------------------------
  24. ' Set the registry key to read
  25. '---------------------------------------------------------------------
  26.  
  27. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\%.0\Outlook\Security\OutlookSecureTempFolder"
  28.  
  29. '---------------------------------------------------------------------
  30. ' Read SecureTempFolder from the registry
  31. '---------------------------------------------------------------------
  32.  
  33. Select Case Left(Outlook.Version, 2)
  34. Case "9.": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "9"))
  35. Case "10": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "10"))
  36. Case "11": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "11"))
  37. Case "12": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "12"))
  38. Case "14": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "14"))
  39. Case Else
  40. MsgBox "Cannot determine your Outlook version.", vbCritical + _
  41. vbOKOnly, "Delete OLK"
  42. Exit Sub
  43.  
  44. End Select
  45.  
  46. '---------------------------------------------------------------------
  47. ' VBA does not provide comfortable functions to delete files, so we use
  48. ' VB-Script.
  49. '---------------------------------------------------------------------
  50.  
  51. Set objFSO = CreateObject("Scripting.FileSystemObject")
  52.  
  53. '---------------------------------------------------------------------
  54. ' Delete all files in the SecureTempFolder (True = force deleting)
  55. '---------------------------------------------------------------------
  56.  
  57. Call objFSO.DeleteFile(strOLK & "*.*", True)
  58.  
  59. '---------------------------------------------------------------------
  60. ' Reference the SecureTempFolder
  61. '---------------------------------------------------------------------
  62.  
  63. Set objFolder = objFSO.GetFolder(strOLK)
  64.  
  65. '---------------------------------------------------------------------
  66. ' Open the folder if it is not empty
  67. '---------------------------------------------------------------------
  68.  
  69. If objFolder.Files.Count Then Call Shell("explorer.exe " & strOLK)
  70.  
  71. '---------------------------------------------------------------------
  72. ' Clean Up
  73. '---------------------------------------------------------------------
  74.  
  75. Set objFolder = Nothing
  76. Set objFSO = Nothing
  77. Set objWsh = Nothing
  78. End Sub