Sender Properties

E

elenev

Hello,

I need to programatically access some information about a sender of an
email in Outlook.

In Outlook itself, I can rigth-click on the message sender, click Add
to Contacts, and then, when I open this contact up from Contacts, I
have not only his name and email, but his phone number, company,
department, etc. and other info recieved through Exchange or some
header.

Well, I need that information and it seems that MailItem only provides
me access to SenderName and SenderEmailAddress.

Is there any way I can programmatically access that information i.e. is
their a DOM way to retrieve the info that you can get by the manual
method described above?

Thanks in advance,
elenev
 
G

Guest

Outlook doesn't maintain a direct programmatic link between the sender of an
e-mail and a possible Contact record that was previously created from that
sender. Your only choice is to use the sender's name or e-mail address with
the Restrict or Find method on a folder's Items collection (or the
AdvancedSearchObject) to retrieve an actual ContactItem object.

Here's a function for using the e-mail address to retrieve a Contact. Just
pass a previously instantiated MAPIFolder object that is stores the Contact
in question (you can use NameSpace.GetDefaultFolder to get the MAPIFolder
object for the default Contacts folder if you like).

Function GetContactByEmailAddress(email As String, ContactFolder As
Outlook.MAPIFolder) As ContactItem
Dim objItems As Outlook.Items, objRItems As Outlook.Items

Set objItems = ContactFolder.Items
Set objRItems = objItems.Restrict("[E-mail] = '" & email & "'")

If objRItems.Count = 0 Then Exit Function
Set GetContactByEmailAddress = objRItems.Item(1)
End Function
 
E

elenev

Eric,

Thank you for your explanation. I am sure your code will prove very
useful.

However, I most likely do NOT yet have the contact in the default
Contacts folder. The only source for all of that information that I
have is the information that seems to have come with the email.

Example: I receive an email from John Doe, whom I do NOT have in my
Contacts folder. Since John Doe works for my company and is on our
exchange server, I can right-click his name in the email, manually add
him to Contacts or click on "Outlook Properties". If I do that, I can
see a lot of information about this contact which I did not have
previously such as Company, Department, Phone Number, Fax, etc.

This is the information I am after, not the details of a contact who
already exists in my Contacts folder.

Is this unrealistic?

Thanks again for all your help,
Vadim
 
D

Dmitry Streblechenko

The information does not come with the e-mail itself. If the message was
sent from outside of your EX domain, the e-mail only has the sender's name
and address.
In case of EX, the message has the sender's entry id, which can be used to
open the corresponding GAL object which contains the properties that you
need.

On the low level (MAPI in C++ or Delphi), you will need to retrieve the
PR_SENDER_ENTRYID property from the message, then use it to call
IAddrBook::OpenEntry. You can them retrieve the PR_COMPANY_NAME,
PR_OFFICE_TELEPHONE_NUMBER, etc from the returned IMailUser object. Look at
the message with OutlookSpy - select the message, click Imessage button on
the OutlookSpy toolbar, select the PR_SENDER_ENTRYID property, RMB, select
IMAPISession::OpenEntry.

if you want to use a higher level API, you are pretty much limited to CDO
1.21 or Redemption, both of which expose the Sender property on the
messages. The address entry returned from the Sender property allows to use
the Fields() collection to retrieve various MAPI properties
(PR_COMPANY_NAME, etc).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
E

elenev

Thank you Dmitry,

I had a nagging suspicion that all of this information was not actually
sent in the header and was only available through some directory query
that Outlook just did for me.. What I was hoping for would've been way
too convenient for me and a hell of a network drag for everyone else...
;)

I really don't have the ability to install CDO or Redemption on all of
the client computers and since I am integrating it with Access, I can't
use C++ or Java and work with low-level abstraction. I guess I'll just
stick to importing names and email addresses.

Again, Dmitry and Eric, thank you for your help. Best regards,
Vadim
 

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