Search code examples
pythonoutlookpywin32

Creating folders in outlook 2010 using python


I know how to get the name of folders in outlook 2010 using the code below:

import win32com.client

ol = win32com.client.Dispatch("Outlook.Application")
ns = ol.GetNamespace("MAPI")
inbox = ns.Folders(6).Folders(2)

How can I add a folder in Folder(2)? I tried the Folders.Add Method method as mentioned in http://support.microsoft.com/kb/208520 but fail.


Solution

  • I think you have made a small mistake, the Add function is the function of Folders. Not a certain Folder like Folders(2)

    You can try the code below and it should work:

    import win32com.client
    
    ol = win32com.client.Dispatch("Outlook.Application")
    ns = ol.GetNamespace("MAPI")
    inbox = ns.Folders(6).Folders(2)
    inbox.Folders.Add("My Folder Src")