[python-win32] Outlook Addin Help

Bill Burns billburns at pennswoods.net
Fri May 12 18:33:56 CEST 2006


[Bobby]

> Do you by chance still have a reference to the MAPI namespace open or
> maybe some folder or item you referenced during execution?

Maybe, I'm still getting the hang of this Windows programming thing :-)

I do have references to -> the CurrentFolder, Sent Mail Folder and
SentMail Items and I don't believe I'm explicitly closing/releasing or
deleting these references anywhere in my code.

Most of my addin is virtually the same as outlookAddin.py
(...\site-packages\win32com\demos\outlookAddin.py) *but* my ButtonEvent
looks like this:

<code>

class ButtonEvent:
     def Init(self, application, activeExplorer):
         self.application = application
         self.activeExplorer = activeExplorer

     def Close(self):
         self.application = None
         self.activeExplorer = None
         self.close()

     def OnClick(self, button, cancel):
         locale.setlocale(locale.LC_NUMERIC, "C")

         # Get the ID of the folder we're currently in.
         currentFolder = self.activeExplorer.CurrentFolder
         currentFolderID = \
         currentFolder.Parent.StoreID, currentFolder.EntryID

         # Get the ID of the 'Sent Items' folder.
         sentFolder = \
 
self.application.Session.GetDefaultFolder(constants.olFolderSentMail)
         sentFolderID = sentFolder.Parent.StoreID, sentFolder.EntryID

         # If we're in the 'Sent Items'...
         if currentFolderID[1] == sentFolderID[1]:
             self.getSentEmailInfo()
         else: # We're not in 'Sent Items'.
             self.folderError()

     def getSentEmailInfo(self):
         sentMailItem = self.activeExplorer.Selection.Item(1)
         try:
             To = sentMailItem.To
             CC = sentMailItem.CC
             BCC = sentMailItem.BCC
             Subject = sentMailItem.Subject
             Body = sentMailItem.Body
         except: # Don't forget to change this.
             print "Error retrieving infomation from the Sent mail item!"
         self.createMailMessage(To, CC, BCC, Subject, Body)

     def createMailMessage(self, To, CC, BCC, Subject, Body):
         # There's usually a 'download' link in the body of the
         # email, if we find it, we'll use it.
         site = re.findall("http://.*", Body)
         if site:
             link = site[0].strip("\r")  + "/addendum"
         else:
             link = ""
         mailMessage = self.application.CreateItem(constants.olMailItem)
         mailMessage.To = To
         mailMessage.CC = CC
         mailMessage.BCC = BCC
         if "RE:" in Subject:
             mailMessage.Subject = Subject
         else:
             mailMessage.Subject = "RE: " + Subject
         mailMessage.Body = \
         "A new addendum has been issued for this project.\n\n%s" % link
         #~ mailMessage.Save()
         mailMessage.Display()

     def folderError(self):
         errMsg = \
         "You must be in the 'Sent Items' Folder to use this tool!"
         win32api.MessageBox(0,
                             errMsg,
                             'Folder Error',
                             win32con.MB_ICONEXCLAMATION)

</code>

I guess I'll try and delete some of these folder and mail objects and 
see what happens.

Thanks,

Bill


More information about the Python-win32 mailing list