[python-win32] Outlook Addin Help

Metz, Bobby W, WWCS bwmetz at att.com
Fri May 12 21:25:13 CEST 2006


I honestly can't remember if folder references in VB were required to be released, or should I say Microsoft "suggested" it.  It's thankfully been way TOO LONG since I last touched VB and Outlook to remember, but I definitely remember the MAPI namespace references had to be set to Nothing.  VB would look something like this.

	outlookApp = CreateObject("Outlook.Application")
	olNameSpace = outlookApp.GetNameSpace("MAPI")
	olActiveExplorer = outlookApp.ActiveExplorer

Based on your code snippet below, I don't know if your referencing the MAPI namespace.  It may not be required if you're just referencing current and default folders using ActiveExplorer.  Sorry man, I just don't remember enough about it.  I only dabbled as it was.  Hope this helps.

Bobby

-----Original Message-----
From: Bill Burns [mailto:billburns at pennswoods.net]
Sent: Friday, May 12, 2006 9:34 AM
To: Metz, Bobby W, WWCS
Cc: Mark Hammond; python-win32 at python.org
Subject: Re: [python-win32] Outlook Addin Help


[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