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

How to determine whether a message was inbound or outbound



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 14th 06, 02:41 PM posted to microsoft.public.outlook.program_vba
Andy Bowles
external usenet poster
 
Posts: 6
Default How to determine whether a message was inbound or outbound

Given a mailItem which has .Sent = True, I want to determine whether it
was outbound (ie sent from this mailbox), or inbound (ie sent to this
mailbox).

I can't rely on the location of the message, because it may have been
moved from the Inbox or from Sent Items. I'm also not keen on using
the sender/recipient addresses, because of the possibility of someone
changing their sender address, or sending an email to themselves.

Testing for the presence of PR_RECEIVED_BY_ADDRTYPE seems to work:

Public Function IsInboundMessage(itm As Outlook.MailItem) As Boolean
Dim ssn As New MAPI.Session
Dim msg As MAPI.Message
Dim typ As String

ssn.Logon , , False, False, 0 ' Use the existing Outlook session
Set msg = ssn.GetMessage(itm.EntryID, itm.Parent.StoreID)

On Error Resume Next
typ = msg.Fields(CdoPR_RECEIVED_BY_ADDRTYPE).Value

If Err.Number 0 Then
Err.Clear
IsInboundMessage = False
Else
IsInboundMessage = True
End If

On Error GoTo 0

ssn.Logoff
Set ssn = Nothing
Set msg = Nothing
End Function

Is this the right way to do this? And is it reliable?

Thanks.

Andy Bowles

Ads
  #2  
Old September 15th 06, 07:04 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default How to determine whether a message was inbound or outbound

Am 14 Sep 2006 05:41:14 -0700 schrieb Andy Bowles:

That´s right and reliable, sent items do not have any pr_received*
properties.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


Given a mailItem which has .Sent = True, I want to determine whether it
was outbound (ie sent from this mailbox), or inbound (ie sent to this
mailbox).

I can't rely on the location of the message, because it may have been
moved from the Inbox or from Sent Items. I'm also not keen on using
the sender/recipient addresses, because of the possibility of someone
changing their sender address, or sending an email to themselves.

Testing for the presence of PR_RECEIVED_BY_ADDRTYPE seems to work:

Public Function IsInboundMessage(itm As Outlook.MailItem) As Boolean
Dim ssn As New MAPI.Session
Dim msg As MAPI.Message
Dim typ As String

ssn.Logon , , False, False, 0 ' Use the existing Outlook session
Set msg = ssn.GetMessage(itm.EntryID, itm.Parent.StoreID)

On Error Resume Next
typ = msg.Fields(CdoPR_RECEIVED_BY_ADDRTYPE).Value

If Err.Number 0 Then
Err.Clear
IsInboundMessage = False
Else
IsInboundMessage = True
End If

On Error GoTo 0

ssn.Logoff
Set ssn = Nothing
Set msg = Nothing
End Function

Is this the right way to do this? And is it reliable?

Thanks.

Andy Bowles

 




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
cannot turn off outbound email scanning Cheryl King Outlook Express 7 July 4th 06 04:45 AM
Whats this about the inbound and outbound... Chris Redfield Outlook Express 5 June 3rd 06 10:58 AM
Determine the file extension of this attachment? George Hester Outlook and VBA 2 April 24th 06 11:41 PM
Determine if a Folder contains a UserProperty Rog Add-ins for Outlook 3 April 10th 06 06:54 PM
Stationery name appears in plain-text outbound message Steve H Outlook Express 7 January 26th 06 03:45 AM


All times are GMT +1. The time now is 06:10 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.