Determining the account of an email

  • Thread starter Sean Farrar (Intechrity)
  • Start date
S

Sean Farrar (Intechrity)

I want determine the account an email was received so I can move it to a
folder for that account. (Yes I know that rules will do this for me but my
rules will not work unless I am connected to the exchange server, even though
they are client side rules).

Is there a way to determine the account in code?
 
K

Ken Slovak - [MVP - Outlook]

The receiving email address is not exposed in the Outlook object model, it's
available in lower level API's such as CDO 1.21 or Extended MAPI or
Redemption as PR_RCVD_REPRESENTING_EMAIL_ADDRESS at property tag 0x0078001E.
If Exchange is the receiving account the result would be an Exchange DN, not
an SMTP address though.




"Sean Farrar (Intechrity)" <Sean Farrar
(Intechrity)@discussions.microsoft.com> wrote in message
news:[email protected]...
 
S

Sean Farrar (Intechrity)

I have five accounts (1 Exchange and 4 SMTP).

Ken Slovak - said:
The receiving email address is not exposed in the Outlook object model, it's
available in lower level API's such as CDO 1.21 or Extended MAPI or
Redemption as PR_RCVD_REPRESENTING_EMAIL_ADDRESS at property tag 0x0078001E.
If Exchange is the receiving account the result would be an Exchange DN, not
an SMTP address though.




"Sean Farrar (Intechrity)" <Sean Farrar
(Intechrity)@discussions.microsoft.com> wrote in message
 
K

Ken Slovak - [MVP - Outlook]

I don't care if you have 100 email accounts, you still would have to read
that MAPI property and if you get an Exchange DN and want an SMTP address
you'd have to convert it.
 
S

Sean Farrar (Intechrity)

So how do I read that property and convert it?

Ken Slovak - said:
I don't care if you have 100 email accounts, you still would have to read
that MAPI property and if you get an Exchange DN and want an SMTP address
you'd have to convert it.
 
K

Ken Slovak - [MVP - Outlook]

What language are you working with and what development platform?

You can use CDO 1.21 or Extended MAPI or a MAPI wrapper such as Redemption
for this. CDO is not supported for .NET code and is an optional
installation, Extended MAPI is not supported for .NET code and is C++ or
Delphi only, Redemption and other MAPI wrappers are usable in COM and .NET
languages.

Here's a CDO example using VBA code:

Function GetAccount(sEntryID As String) As String
' EntryID of the email to check

Dim oSession As MAPI.Session
Dim oRecip As MAPI.Recipient
Dim oAE As MAPI.AddressEntry
Dim oMessage As MAPI.Message
Dim oDummy As MAPI.Message
Dim sEmail As String

Const PR_RCVD_REPRESENTING_EMAIL_ADDRESS _
As Long = &H78001E

Const PR_EMAIL As Long = &H3003001E

'usable with piggy-back logon only when Outlook is already running
Set oSession = New MAPI.Session
oSession.Logon "", "", False, False

Set oMessage = oSession.GetMessage(sEntryID)
sEmail = oMessage.Fields(PR_RCVD_REPRESENTING_EMAIL_ADDRESS)

If (Instr(1, sEmail, "/cn", vbTextCompare) >0) Then ' EX address
Set oDummy = oSession.Inbox.Messages.Add("Test subject", _
"Test body")

Set oRecip = oDummy.Recipients.Add("", sEmail)
oRecip.Resolve
If (oDummy.Recipients.Resolved) Then
Set oAE = oRecip.AddressEntry

GetAccount = oAE.Fields(PR_EMAIL)
' in cached EX mode you do not get PR_EMAIL
' in that case you must read PR_EMS_AB_PROXY_ADDRESSES
' at &H800F101E, a multivalued string property. Iterate the
array
' that is returned looking for the one that starts with
"SMTP:" - the
' default SMTP address for that EX recipient.
Else
GetAccount = "" 'failure
End If
Else
GetAccount = sEmail
End If

oSession.Logoff
' now set all objects = Nothing
End Function

Of course the code would be somewhat different for Redemption or Extended
MAPI.
 
Top