PythonWin Outlook connection

michael montagne montagne at boora.com
Mon May 14 14:55:48 EDT 2001


OK, got it working.  I deleted all the files in c:\python21\win32com\gen_py
and now everything works.  Can someone explain that to me?
I don't have to do that on my machine.  I thought it was better to run
makepy and enable early binding by using
objOut = win32com.client.Dispatch("Outlook.Application.9").  But now that
same line only works if I don't run makepy.
I'm afraid I don't completely understand.

-mjm


"michael montagne" <montagne at boora.com> wrote in message
news:PPTL6.47628$FS3.516192 at sjc-read.news.verio.net...
> Thanks Mark but no luck.  I also have no problems on my win98 machine at
> home.  It's only where it has to be that doesn't work.  Here is my code:
> Can you see anything else:
>
> import win32com, sys, string, win32api, urllib
> import win32com.client.dynamic
> import RFIData
>
>
> class myURLOpener(urllib.FancyURLopener):
>
>     def setpasswd(self, user, passwd):
>         self.__user = user
>         self.__passwd = passwd
>
>     def prompt_user_passwd(self, host, realm):
>         return self.__user, self.__passwd
>
> def CalcIsOpen(str):
>       import re
>       regexp=re.compile(r"( RFI#.* NEW )")
>       a=str
>       if regexp.search(a):
>          return "true"
>       else:
>          return "false"
>
> def main():
>    ##try:
>         import win32com.client
>         import traceback
>         import time
>         import re
>
> #gencache.EnsureModule('{00062FFF-0000-0000-C000-000000000046}',0,9,0)
>         #strPrefix="h:\\proj\\test\\rfi\\"
>         strPrefix="h:\\proj\\98011\\rfi\\"
>         #objOut=EnsureDispatch("Outlook.Application.9")
>         objOut = win32com.client.Dispatch("Outlook.Application.9")
>         objNamespace=objOut.GetNamespace("Mapi")
>         objNamespace.Logon()
>         folder=objNamespace.Folders.Item("Public
Folders").Folders.Item("All
> Public folders").Folders.Item("Proj").Folders.Item("98011 UC
> Davis").Folders.Item("UCD RFI's")
>         oldfolder=objNamespace.Folders.Item("Public
> Folders").Folders.Item("All Public
> folders").Folders.Item("Proj").Folders.Item("98011 UC
> Davis").Folders.Item("zRFIArchive")
>         cnt=folder.Items.Count
>         files=[]
>         emails=[]
>         daoEngine=win32com.client.Dispatch("DAO.DBEngine.36")
>         db=daoEngine.OpenDatabase('H:\\proj\\98011\\data\\UCDRFI.mdb')
>         i=1
>         print str(cnt) + " emails found to process"
>         while i <= cnt:
>
>             try:
>                 objemail=folder.Items(i)
>                 strbody=objemail.body
>                 strsubject=objemail.subject
>                 isopen=CalcIsOpen(strsubject)
>                 try:
>                     print str(cnt-i) + " ---- " + strsubject
>                 except:
>                     tb= sys.exc_info()[2]
>                     print traceback.extract_tb(tb)[0]
>                     print str(cnt-i) + " ---- "
>                 ii=string.find(strbody,"http:")
>                 if ii != -1:
>                     strurl=strbody[ii:]
>                     istart=string.find(strurl,"UNID")
>                     iend=string.find(strurl,"?Opendocument")
>                     strFileName=strurl[istart+5:iend]
>                     urlopener = myURLOpener()
>                     urlopener.setpasswd("consultant", "ae")
>                     strOutFile=strPrefix + strFileName + ".html"
>                     fp=urlopener.retrieve(strurl,strOutFile)
>                     urlopener.cleanup
>                     ##UpdateDatabase
>
>                     a=RFIData.RFIData(strOutFile)
>                     rs=db.OpenRecordset('SELECT * FROM tblRFI WHERE RFI='
+
> a.RFI)
>
>                     if rs.EOF:
>
>                         rs.AddNew()
>                         rs.Fields('Title').Value=a.Title
>                         rs.Fields('RFI').Value=a.RFI
>                         rs.Fields('Specification').Value=a.Specification
>                         rs.Fields('Drawing').Value=a.Drawing
>                         rs.Fields('Reference').Value=a.Reference
>                         rs.Fields('InitiatedBy').Value=a.InitiatedBy
>                         try:
>                             rs.Fields('RespondBy').Value=a.RespondBy
>                         except:
>                             tb= sys.exc_info()[2]
>                             print traceback.extract_tb(tb)[0]
>                             print a.RespondBy + " is not a valid date"
>                         rs.Fields('Subject').Value=a.Subject
>                         rs.Fields('Filename').Value=a.FileName
>                         try:
>                             rs.Fields('Sent').Value=a.Sent
>                         except:
>                             tb= sys.exc_info()[2]
>                             print traceback.extract_tb(tb)[0]
>                             rs.Fields('Sent').Value=a.RespondBy
>                         rs.Fields('Question').Value=a.Question
>                         rs.Fields('Response').Value=a.Response
>                         rs.Fields('IsOpen').Value=isopen
>                         rs.Update()
>                     else:
>
>                         rs.Edit()
>                         rs.Fields('Title').Value=a.Title
>                         rs.Fields('RFI').Value=a.RFI
>                         rs.Fields('Specification').Value=a.Specification
>                         rs.Fields('Drawing').Value=a.Drawing
>                         rs.Fields('Reference').Value=a.Reference
>                         rs.Fields('InitiatedBy').Value=a.InitiatedBy
>                         try:
>                             rs.Fields('RespondBy').Value=a.RespondBy
>                         except:
>                             tb= sys.exc_info()[2]
>                             print traceback.extract_tb(tb)[0]
>                             print a.RespondBy + " is not a valid date"
>                         rs.Fields('Subject').Value=a.Subject
>                         rs.Fields('Filename').Value=a.FileName
>                         try:
>                             rs.Fields('Sent').Value=a.Sent
>                         except:
>                             tb= sys.exc_info()[2]
>                             print traceback.extract_tb(tb)[0]
>                             rs.Fields('Sent').Value=a.RespondBy
>                         rs.Fields('Question').Value=a.Question
>                         rs.Fields('Response').Value=a.Response
>
> rs.Fields('Created').Value=time.strftime("%m/%d/%Y",time.localtime())
>                         rs.Fields('IsOpen').Value=isopen
>                         rs.Update()
>
>                     emails.append(objemail)
>                 else:
>                     print "No URL found:"
>             except:
>                 i= i+1
>                 print "Skipping "
>                 tb= sys.exc_info()[2]
>                 print traceback.extract_tb(tb)[0]
>                 continue
>             i= i+1
>
> ##    except:
> ##        ##Cleanup
> ##        import sys
> ##        print "Error-Aborting"
> ##        print sys.exc_info()
> ##        rs.Close()
> ##        db.Close()
> ##        objNamespace.Logoff()
> ##        raw_input("Hit return to exit")
>
>         ##Cleanup
>         try:
>             rs.Close()
>         except UnboundLocalError:
>             print "Recordset Never Opened. "
>         try:
>             db.Close()
>         except UnboundLocalError:
>             print "Databse never Opened"
>         ##Delete emails that were processed correctly
>         if len(emails)>0:
>             print "Moving processed emails"
>         for e in emails:
>             try:
>                 print e
>             except:
>                 tb= sys.exc_info()[2]
>                 print traceback.extract_tb(tb)[0]
>                 print " ---- "
>             try:
>                 etest=oldfolder.Items(e.subject)
>                 etest.delete()
>                 e.move(oldfolder)
>             except:
>                 e.move(oldfolder)
>
>         objNamespace.Logoff()
>         raw_input("Hit return to exit")
>
> if __name__=='__main__':
>     main()
> else:
>     print "RFI loaded as module. Run Main() to begin"
>
>
>
>
>
>





More information about the Python-list mailing list