Want e-mail addresses from items in my inbox

S

Stanley

I have the following code:
Private Sub myOlApp_InboxItems()
Dim myOlApp As Outlook.Application
Dim myfolder As Outlook.MAPIFolder
Dim myitems As Items
Dim mynamespace As NameSpace
Dim n As Integer
Set myOlApp = CreateObject("Outlook.Application")
Set mynamespace = myOlApp.GetNamespace("MAPI")
Set myfolder = mynamespace.GetDefaultFolder(olFolderInbox)
Set myitems = myfolder.Items
MsgBox myitems.Count
n = 1
MsgBox myitems(n) 'this gives me the subject of the 1st e-mail in my inbox
End Sub
From this I can loop and see the subject of each e-mail in my inbox. What I
would like to see is the e-mail address of the sender and the date it was
sent.
Any ideas how I can code this?
Thanks,
Stanley
 
K

Ken Slovak - [MVP - Outlook]

Instantiate an Outlook.MailItem from that myitems(n). Then read any
properties you want from the MailItem such as ReceivedTime or
SenderEmailAddress.
 
S

Stanley

I did this and its works fine except I can't get the SenderEmailAddress (it
is not there).
I can get "ReceivedTime" and "SenderName".
I am using Outlook 2002.
Any ideas?
Thanks,
Stanley
 
K

Ken Slovak - [MVP - Outlook]

SenderEmailAddress was added in Outlook 2003. A hack workaround would be to
create a reply and get the address from that:

Dim oReply As Outlook.MailItem
Set oReply = oMail.Reply
strAddress = oReply.Recipients.Item(1).Address
oReply.Close olDiscard
 
S

Stanley

This worked out OK. except when I tried to get an email sender from our own
email server i got /O=ZONI GROUP/OU=FIRST
ADMINISTRATIVEGROUP/CN=RECIPIENTS/CN=STANLEY.
I tried this is Outlook 2003 and and got the same result using
SenderEMailAddress.
Any ideas,
Thanks,
Stanley
 
K

Ken Slovak - [MVP - Outlook]

To convert a Exchange DN (distinguished name) type email address into an
SMTP address you would need to use a lower level API such as CDO 1.21 or
Redemption (www.dimastr.com/redemption) or Extended MAPI (C++ or Delphi
only). Depending on which API you use and what version of Outlook and
whether or not cached mode is being used you then can retrieve the MAPI
property for the SMTP address.

See http://www.outlookcode.com/threads.aspx?forumid=5&messageid=12791 for
some additional information and code samples on this.
 

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