A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Determining the account of an email



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 28th 07, 01:28 PM posted to microsoft.public.outlook.program_vba
Sean Farrar (Intechrity)
external usenet poster
 
Posts: 1
Default Determining the account of an email

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?
  #2  
Old March 28th 07, 02:08 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Determining the account of an email

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sean Farrar (Intechrity)" Sean Farrar
wrote in message
...
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?


  #3  
Old March 28th 07, 06:56 PM posted to microsoft.public.outlook.program_vba
Sean Farrar (Intechrity)
external usenet poster
 
Posts: 2
Default Determining the account of an email

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

"Ken Slovak - [MVP - Outlook]" wrote:

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sean Farrar (Intechrity)" Sean Farrar
wrote in message
...
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?



  #4  
Old March 28th 07, 07:53 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Determining the account of an email

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sean Farrar (Intechrity)"
wrote in message ...
I have five accounts (1 Exchange and 4 SMTP).


  #5  
Old March 29th 07, 12:36 AM posted to microsoft.public.outlook.program_vba
Sean Farrar (Intechrity)
external usenet poster
 
Posts: 2
Default Determining the account of an email

So how do I read that property and convert it?

"Ken Slovak - [MVP - Outlook]" wrote:

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sean Farrar (Intechrity)"
wrote in message ...
I have five accounts (1 Exchange and 4 SMTP).



  #6  
Old March 29th 07, 02:38 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Determining the account of an email

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sean Farrar (Intechrity)"
wrote in message ...
So how do I read that property and convert it?


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2002--How do I change account which email account is active? Dana Outlook - General Queries 0 December 26th 06 04:19 PM
determining Senders smtp address Paul Young Outlook and VBA 4 November 2nd 06 05:18 PM
Determining public folder server from Windows Outlook Tim Murray Outlook - Calandaring 18 September 20th 06 01:57 AM
Determining When and Who schedules an appointment for a shared cal K. Diotte Outlook - Calandaring 0 September 11th 06 03:23 PM
Determining account being used Scott Outlook and VBA 2 January 25th 06 04:39 PM


All times are GMT +1. The time now is 12:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.