pythonoutlookrpcwin32comcom-automation

How can i get rid of the exception 'The RPC server is unavailable' while saving the Outlook message via python?


I'm working with win32com library and try to save mail i've just created. I use .CreateItem() function to create mail instance and try to save it using mail.Save() Unfortunately i get this exception (-2147023174, 'The RPC server is unavailable.', None, None). Thank you very much in advance.


Solution

  • Most probably the Outlook.exe process has finished its work and gone. Check out the list of running processes when you got this kind of errors.

    You may try to get an instance of the Explorer window to stop Outlook from closing by using Explorers.Add method which creates a new instance of the explorer window.

    Sub DisplayDrafts()  
     Dim myExplorers As Outlook.Explorers  
     Dim myOlExpl As Outlook.Explorer  
     Dim myFolder As Outlook.Folder  
     
     Set myExplorers = Application.Explorers  
     Set myFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)  
     Set myOlExpl = myExplorers.Add(myFolder, olFolderDisplayNoNavigation)  
    ' myOlExpl.Display  
    End Sub