Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2003

Tip: Looking for answers? Try searching our database.

Problem with GetMessage on other mailboxes.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ward Horsfall - 17 Sep 2003 12:03 GMT
Hi,

I appologize for the length of this post - but it is the easiest way to get
the message across.
I am trying to use some VBA code in Outlook XP to get the senders SMTP
address. The code works
fine if I am processing a message in my own inbox. However if I am accessing
another mailbox
like one I have full control over or say a public folder then I come up with
an error. The
one below is me accessing a mailbox that I have full read/write access to..
What am I doing
wrong? Is there another way I should code for such a situation..

Thanks

Ward.

Code :::: --------

Sub get_sender_smtp_address()

  Dim oSession As MAPI.Session
  Dim objSender As MAPI.AddressEntry
  Dim itm As Outlook.mailitem
  Dim strMsg As String
  On Error Resume Next
  Set itm = Application.ActiveExplorer.Selection.Item(1)

  ' Create a MAPI session.

  Set oSession = CreateObject("MAPI.Session")
  oSession.Logon "", "", False, False
  Err.Clear
  Set objMsg = oSession.GetMessage(itm.EntryID)

  ' The call above fails if not own own mailbox.
  '
  ' Err Code : -2147220991 if not own mailbox.
  '            [MAPI - [MAPI_E_UNKNOWN_ENTRYID(80040201)]]

  ' Works fine if sitting in current owned inbox.

  If Err <> 0 Then
       MsgBox Err
       MsgBox Err.Description
  End If

  Set oSndr = objMsg.Sender

 'Get the actual email address
  sAddress = oSndr.Address

 ' Check if it is an Exchange object
  If Left(sAddress, 3) = "/o=" Then

       ' Get the SMTP address
       strAddressEntryID = oSndr.ID
       sAddress =
oSession.GetAddressEntry(strAddressEntryID).Fields(CdoPR_EMAIL).Value
   End If

 'Display the information in a MsgBox

   MsgBox sAddress

 oSession.Logoff

 Set oNS = Nothing
 Set oItm = Nothing
 Set obj = Nothing
 Set oSession = Nothing
 Set oMsg = Nothing
 Set oSndr = Nothing

End Sub
Sue Mosher [MVP] - 17 Sep 2003 13:09 GMT
In general, you'll get more consistent results if you pass both EntryID and StoreID to the GetMessage function. The StoreID tells CDO what part of the folder hierarchy to look in.
Signature

Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
    Microsoft Outlook Programming: Jumpstart
    for Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx 

> Hi,
>
[quoted text clipped - 38 lines]
>
>    ' Works fine if sitting in current owned inbox.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.