Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm working on access app and I'm trying to send a mail with a report attached. Then I want to recover that mail sent and display it. But I can't do this with EntryId property, because this key changes everytime it moves from outbox to mailsent box.
Can anyone help me?
Thanks.
Posted
Updated 17-Jul-20 11:39am

1 solution

Yep, you're right, the EntryID changes.
I've used Message ID, but you can only see/get it in the message header.

VB
Public OlSentFolder As Outlook.Folder ' Global variable

Dim olPA As Outlook.PropertyAccessor
Dim messageID as String
Dim myOutlook As Outlook.Application
Dim olNamespace As Outlook.NameSpace

Set myOutlook = GetObject(, "Outlook.Application")
Set olNamespace = myOutlook.GetNamespace("MAPI")
Set OlSentFolder = olNamespace.GetDefaultFolder(olFolderSentMail)

' get the PropertyAccessor
' i is the index of the mail message you are working with
Set olPA = olSentFolder.Items(i).PropertyAccessor
' Message-ID, specified by RFC 2822
' cannot use EntryID - it changes
messageID = olPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1035001E")	

The Message ID will look something like this: <008401cef84c$5a2d3c40$0e87b4c0$@company.com>

Here is some example code to get a message by MessageID:
VB
Function GetEmailItemByID(id As String) As Outlook.MailItem
    Dim findItems As Outlook.Items
    Dim query As String
    
    query = "@SQL=""http://schemas.microsoft.com/mapi/proptag/0x1035001E"" = '" & id & "'"
    ' get email object by message ID
    Set findItems = OlSentFolder.Items.Restrict(query)
    If findItems.Count <> 1 Then
        Debug.Print "Something is wrong - MessageID not found or >1 found."
    Else
        Set GetEmailItemByID = findItems.Item(1)
    End If
End Function
 
Share this answer
 
Comments
Tony Hill 18-Jul-20 12:37pm    
Unlikely that the original poster is still interested as the question is 5 years old.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900