[python-win32] python-win32 Digest, Vol 57, Issue 22

Antony Joseph antonyjoseph89 at gmail.com
Mon Dec 24 09:43:53 CET 2007


Hi,

I am try to print all the message in my mailbox . its not working
inbox = session.Inbox
i print the value of inbox its gives <COMObject <unknown>>
I think its not getting the inbox ?

<code>
#
# inbox.py
# test case for access to Exchange; run through the
#   hard-coded user's inbox and list the subjects of each email.
#

import win32com.client
session = win32com.client.gencache
>
> .EnsureDispatch ("MAPI.Session")
> session.Logon ()
>
inbox = session.Inbox

print  inbox

when I try to print the inbox :
inbox = <COMObject <uknown>>

can anybody tell whats wrong in Outlook.?


> messages = inbox.Messages
> message = messages.GetFirst ()
> while message:
>   print "subject: ", message.Subject
>   message = messages.GetNext ()
>
> session.Logoff ()
>
> </code>




On Dec 21, 2007 4:30 PM, <python-win32-request at python.org> wrote:

> Send python-win32 mailing list submissions to
>        python-win32 at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/python-win32
> or, via email, send a message with subject or body 'help' to
>        python-win32-request at python.org
>
> You can reach the person managing the list at
>        python-win32-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of python-win32 digest..."
>
>
> Today's Topics:
>
>   1. how to get mails from Outlook (Antony Joseph)
>   2. Re: how to get mails from Outlook (Tim Golden)
>   3. Operational errorr : (Antony Joseph)
>   4. Re: Operational errorr : (Tim Golden)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 21 Dec 2007 12:03:27 +0530
> From: "Antony Joseph" <antonyjoseph89 at gmail.com>
> Subject: [python-win32] how to get mails from Outlook
> To: python-win32 at python.org
> Message-ID:
>        <f14c4c340712202233ua179a9dk56401d863275d930 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> hi,
>
> I am trying to read all the mails in the Inbox from outlook and convert
> those mails into text format in my local path.
>
> Is there any tutorials or any links that can be usefull to me.
>
> Thanks
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/python-win32/attachments/20071221/516acd01/attachment-0001.htm
>
> ------------------------------
>
> Message: 2
> Date: Fri, 21 Dec 2007 08:42:21 +0000
> From: Tim Golden <mail at timgolden.me.uk>
> Subject: Re: [python-win32] how to get mails from Outlook
> Cc: python-win32 at python.org
> Message-ID: <476B7C6D.2090400 at timgolden.me.uk>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Antony Joseph wrote:
> > hi,
> >
> > I am trying to read all the mails in the Inbox from outlook and convert
> > those mails into text format in my local path.
> >
> > Is there any tutorials or any links that can be usefull to me.
>
> Here's an absolutely Noddy example to get you going:
>
> <code>
> #
> # inbox.py
> # test case for access to Exchange; run through the
> #   hard-coded user's inbox and list the subjects of each email.
> #
>
> import win32com.client
>
> session = win32com.client.gencache.EnsureDispatch ("MAPI.Session")
> session.Logon ()
>
> inbox = session.Inbox
> messages = inbox.Messages
> message = messages.GetFirst ()
> while message:
>   print "subject: ", message.Subject
>   message = messages.GetNext ()
>
> session.Logoff ()
>
> </code>
>
> and, aside from the MSDN docs on MAPI.Session, the keyword
> you're looking for is CDO. Here's a couple of useful sites:
>
> http://www.outlookcode.com/article.aspx?id=20
> http://www.cdolive.com/default.htm
>
> BTW, this is all relatively old stuff (although it still works
> fine on my XP-Outlook2003-Exchangewhatever setup). There may
> well be some "preferred" MSActiveNETMailProvider [*] technique
> which is more future-proofed.
>
> If you need more info feel to come back and ask.
>
> TJG
>
> [*] Invented, obviously; don't go searching for it!
>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 21 Dec 2007 14:42:39 +0530
> From: "Antony Joseph" <antonyjoseph89 at gmail.com>
> Subject: [python-win32] Operational errorr :
> To: python-win32 at python.org
> Message-ID:
>        <f14c4c340712210112u70b27bbdx39577736a60e66df at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> I am getting Operational Error : when i try get my contacts .
>
> My code :
> import win32com.client
> oOutlook = win32com.client.gencache.EnsureDispatch("Outlook.Application")
> onMAPI = oOutlook.GetNamespace("MAPI")
> ofContacts = onMAPI.GetDefaultFolder(10) # 10=outlook contacts folder
> redemption = oOutlook.CreateObject('Redemption.SafeContactItem')
> for i in range(len(ofContacts.Items)):
>    redemption.Item = ofContacts.Items.Item(i+1)
>    print redemption.Subject
>
> can any one tell me , what i am doing error or please tell me to solve
> this
> problem.
>
>
> My Error:
>
>  File "m1.py", line 5, in <module>
>    redemption = oOutlook.CreateObject('Redemption.SafeContactItem')
>  File
> "C:\Python25\lib\site-packages\win32com\gen_py\00062FFF-0000-0000-C000-00
> 0000000046x0x9x3\_Application.py", line 82, in CreateObject
>    ret = self._oleobj_.InvokeTypes(277, LCID, 1, (9, 0), ((8,
> 1),),ObjectName
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096,
> 'Microsoft
> Off
> ice Outlook', 'The operation failed.', None, 0, -2147221005), None)
>
>
> Antony
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/python-win32/attachments/20071221/c9e399c0/attachment-0001.htm
>
> ------------------------------
>
> Message: 4
> Date: Fri, 21 Dec 2007 09:41:19 +0000
> From: Tim Golden <mail at timgolden.me.uk>
> Subject: Re: [python-win32] Operational errorr :
> Cc: python-win32 at python.org
> Message-ID: <476B8A3F.4090107 at timgolden.me.uk>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Antony Joseph wrote:
> > I am getting Operational Error : when i try get my contacts .
> >
> > My code :
> > import win32com.client
> > oOutlook = win32com.client.gencache.EnsureDispatch("Outlook.Application
> ")
> > onMAPI = oOutlook.GetNamespace("MAPI")
> > ofContacts = onMAPI.GetDefaultFolder(10) # 10=outlook contacts folder
> > redemption = oOutlook.CreateObject('Redemption.SafeContactItem')
>
> Well your error's coming from this line, but for the life
> of me I can't work out what you're trying to do with it,
> since it's not used anywhere else. The MSDN help for Outlook
> _Application.CreateObject [1] suggests that it's a placeholder for
> other methods of creating objects. Maybe you're trying to use
> .CreateItem [2] which seems to be used for creating new contact
> items.
>
> > for i in range(len(ofContacts.Items)):
> >     redemption.Item = ofContacts.Items.Item(i+1)
> >     print redemption.Subject
>
> Ah, I think I see. You're trying to create a contact which
> then appears in the list this displays. I think you'll need
> to save it first with some details as per the Technet link
> below {[2]).
>
> TJG
>
> [1]
>
> http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.outlook._application.createobject.aspx
> [2]
>
> http://www.microsoft.com/technet/scriptcenter/resources/officetips/apr05/tips0426.mspx
>
>
>
> ------------------------------
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
> End of python-win32 Digest, Vol 57, Issue 22
> ********************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20071224/96011e1b/attachment.htm 


More information about the python-win32 mailing list