Accessing shared outlook inbox in python

时间:2015-06-15 15:16:24

标签: python email outlook

I have a shared inbox in outlook and I want to write some code that would get me the emails from the shared inbox. Right now I can get the emails from my main inbox, but I want to do it for another inbox.

This is the code so far:

import os
import win32com.client

outlook = win32com.client.Dispatch('Outlook.Application').GetNamespace('MAPI')
inbox = outlook.GetDefaultFolder(6).Folders('Some Magic Folder')
messages = inbox.Items

My guess is that I shouldn't be looking at the GetDefaultFolder method but something else, but I'm not quite sure where to look at.

1 个答案:

答案 0 :(得分:1)

Namespace类的GetSharedDefaultFolder方法返回一个Folder对象,该对象表示指定用户的指定默认文件夹。

Sub ResolveName() 
  Dim myNamespace As Outlook.NameSpace 
  Dim myRecipient As Outlook.Recipient 
  Dim CalendarFolder As Outlook.Folder 
  Set myNamespace = Application.GetNamespace("MAPI") 
  Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev") 
  myRecipient.Resolve 
  If myRecipient.Resolved Then 
    Call ShowCalendar(myNamespace, myRecipient) 
  End If 
End Sub 

Sub ShowCalendar(myNamespace, myRecipient) 
  Dim CalendarFolder As Outlook.Folder 
  Set CalendarFolder = _ 
  myNamespace.GetSharedDefaultFolder _ 
  (myRecipient, olFolderCalendar) 
  CalendarFolder.Display 
End Sub
相关问题