Reading another inbox

  • Thread starter Scott Fenstermacher
  • Start date
S

Scott Fenstermacher

Hi. I'm trying to access another mailbox to which I have rights. I want to
read the subject, if it contains "New Employee", pass the body onto another
subroutine which will parse the information out for account creation. Every
time I try to access the body method, it fails. The Watch window says
<Method 'Body' of object 'MailItem' failed>. Trying to access the body
through Outlook Spy gives me the security prompt about accessing the body of
an email. When I try to set a MailItem object to the olItem variant, I get
a type mismatch error. Any ideas?

-Scott Fenstermacher

Here is my code.
===========================
Dim objNs As NameSpace
Dim objInbox As MAPIFolder
Dim olMail As Variant
Dim NS As Outlook.Recipient
Dim I As Integer

'On Error Resume Next

Set objNs = Application.GetNamespace("MAPI")
Set NS = objNs.CreateRecipient("Network Support/Help Desk")
NS.Resolve
If NS.Resolved Then
Set objInbox = objNs.GetSharedDefaultFolder(NS, olFolderInbox)
Else
MsgBox "Unable to resolve Network Support Inbox!", vbOKOnly +
vbExclamation, "Error connecting to inbox"
Exit Sub
End If

For Each olMail In objInbox.Items
If InStr(olMail.Subject, "New Employee") > 0 Then
' Dim Email as Outlook.MailItem
' Set Email = olMail
' This gives a type mismatch error!

ParseEmail (olMail.Body)
' This doesn't like the Body method...
End If
Next

Set objInbox = Nothing
Set objNs = Nothing
Set NS = Nothing
 
S

Scott Fenstermacher

Forgot to mention I had tried Object first, then tried Variant (didn't
change it back yet, good point!). I still get the <Method 'Body' of object
'MailItem' failed> message. Works fine from my inbox though.

-Scott Fenstermacher
 
S

Sue Mosher [MVP-Outlook]

You might want to check TypeName(olMail) to see what kind of item you have.

However, I don't see how you can be getting an error that reads <Method
'Body' of object 'MailItem' failed> unless there's some code you're not
showing us. Your snippet below has no object named "MailItem" (which would
be a bad name for an object variable anyway).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Scott Fenstermacher

Got it, it was a security issue. When it worked in my inbox, the lightbulb
went off (albeit dimly) and I dug into the folder permissions and found that
I wasn't given the rights I thought I had been given.

Thanks for your help!

-Scott Fenstermacher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top