Is there an ID field you can use to pair a reply to the sent email?

Outlook version
Outlook 2016 64 bit
Email Account
IMAP
Hi all,

Is there a field within an Outlook mailItem which allows you to store an ID number e.g. 123456 which you can read from their reply email?
I am trying to insert a contactId somewhere in the email which I can read when the person replies and use to make updates to an Access database. I would rather not have to show the contactId in the body of the email. I tried using the 'mileage' field but it came back empty in the reply.

I have tried to capture conversationID from the last sent message in the sent folder and then pair it with the conversationID of the reply email but they don't match up.

The code I used to get the conversationID of the last sent message in the sent folder is:
Dim ns As NameSpace
Dim f As Folder
Dim items As items


Dim mailSent As MailItem

Set ns = Application.Session
Set f = ns.GetDefaultFolder(olFolderSentMail)
Set items = f.items

items.Sort "SentOn", False
Set mailSent = items.Item(items.Count)
Debug.Print mailSent.Subject
Debug.Print "last mail sent: " & mailSent.ConversationID

The code I used to get the conversationID from the reply email is:
Dim oApp As Outlook.Application
Set oApp = GetObject(, "Outlook.Application")
Dim oMail As Outlook.MailItem
Set oMail = oApp.ActiveExplorer.Selection.Item(1)

Debug.Print oMail.ConversationID


Thanks!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Do you want to add a contactid field to the message that matches a contact? If you want to use a unique code that is in the message, the entryid would work.

You can't replace a field that already exists but can add a custom field.
 
Outlook version
Outlook 2016 64 bit
Email Account
IMAP
Hi Diane, thanks for your reply.
I tried the Entry ID but that didn't match between the sent and reply emails unfortunately.
I tried your custom field idea but have come up against an error.

I have two buttons in the Outlook ribbon: the first one sends the email with this code:
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
Dim UserProp As Outlook.UserDefinedProperty
Set oApp = GetObject(, "Outlook.Application")

Set oMail = oApp.CreateItem(olMailItem)
oMail.Display
oMail.To = "franc@workingdata.co.uk"
oMail.Mileage = 1234567890
oMail.Subject = "Unsubscribe"
oMail.UserProperties.Add("contactId", olNumber) = 1234567890
oMail.Save
oMail.Send
I received the email from Outlook to another email address for which I use Thunderbird. I reply with a few words and send the email back. I then try to read the 'contactId' field from the reply email using your code (slightly amended):
Dim UserProp As Outlook.UserDefinedProperty
Dim obj As Object
Dim contactId As Long

Set obj = Application.ActiveExplorer.Selection.Item(1)

On Error Resume Next
Set UserProp = obj.UserProperties.Find("contactId")
If Not UserProp Is Nothing Then
contactId = obj.UserProperties("contactId").Value
MsgBox strCurrent
Else
MsgBox "Field not found"
End If

Set obj = Nothing

End Sub
This brings up the messagebox 'Field not found'. I'm sure I've spelt the custom field the same way in both subs. Any ideas?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Ah yeah, the custom field is not sent with the message.

The thread index in the header should work - as long as the sending server doesn't strip it out.

Original from client:
Thread-Index: AdbFGPx6nS1EldD1QR+/viR5PfRk7QCIIw9A

My message to him does not have a thread id (or a header)
But the reply back has this - using just the first 10 or 20 characters should work.
Thread-Index: AdbFGPx6nS1EldD1QR+/viR5PfRk7QCIIw9AAAimK3AAAdIzAA==
 
Outlook version
Outlook 2016 64 bit
Email Account
IMAP
Hi Diane, I couldn't find 'Thread-Index' as an option for an olMailItem.

When I tried Conversation Index there wasn't the similarity that you showed in your example. How do email clients know how to put together emails into conversation threads? Is that what I'm missing?
 
Similar threads
Thread starter Title Forum Replies Date
S CONTACT FIELD PRINT ORDER Outlook VBA and Custom Forms 1
V Checking for empty field Outlook VBA and Custom Forms 2
V Update new custom field Outlook VBA and Custom Forms 5
HappyDaddy007 "Size" on field chooser/column displaying incorrect value Using Outlook 3
H Information from user defined field into Excel Outlook VBA and Custom Forms 7
I Outlook 2003 shows html code when To: field is empty Using Outlook 7
Terry Sullivan Sender's Name Doesn't Appear in the From Field on Outlook 365/IMAP Using Outlook 2
D Outlook Contacts Notes Field Photos to Smartphone Using Outlook 0
S Custom Field Cannot Be Displayed In Views Outlook VBA and Custom Forms 2
Terry Sullivan Sender Field Displays My E-Mail Address, Not My Name Using Outlook 1
S Create a clickable custom column field Outlook VBA and Custom Forms 0
B User defined field for messages with 'me' in the [To], [Cc] line Using Outlook 0
V Limiting text length in free text field Outlook VBA and Custom Forms 2
C Outlook 2016 Conditional Format for User Defined Field Using Outlook 1
C Copy Outlook contact field value to another field Outlook VBA and Custom Forms 1
A new labeled phone field Using Outlook 4
V Making a Date field mandatory in outlook form Outlook VBA and Custom Forms 2
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
BretAB Is it possible to add a lookup field to a Message form? Outlook VBA and Custom Forms 4
N Exporting IM Address field Using Outlook 2
M Using field names to capture a data element Using Outlook 0
J How to restore field no longer visible in field chooser? Using Outlook 1
S Custom Form, copy user field data to message body Outlook VBA and Custom Forms 12
R What's supposed to appear when just clicking into the search field? Using Outlook 7
A Missing context menu on Location field Using Outlook 2
G Entered data in custom field goes in card and does not stay in list view Outlook VBA and Custom Forms 1
C Changed By field not displaying individual user's name in O365 Shared Mailbox Using Outlook 9
M Making Subject field writable (disable Read Only) Outlook VBA and Custom Forms 2
C Import Outlook 2016 contacts into to: field Using Outlook 1
T Source of Outlook 2016 Address field dropdown "Other Suggestions" Using Outlook 3
S BCM Compulsory field, New opportunity Outlook VBA and Custom Forms 0
M Sudden change in From field - now very short Using Outlook 4
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
J Assess content of User Defined Field in Rule Using Outlook 3
K Contact notes field replicating Using Outlook 6
G Copy Contact field to Appointment Custom Form Field Outlook VBA and Custom Forms 2
Caio "From" field doesn't show extra email addresses in Outlook 2016. Using Outlook.com accounts in Outlook 6
T "From" field font size in table list of emails Using Outlook 0
skyfox VBA to search email subject field for a certain string Outlook VBA and Custom Forms 3
E Inbox field customization Using Outlook 1
A How to get rid of Contacts field when printing emails? Using Outlook 0
George Simpson "Switch to HTML" in Outlook 2016 notes field Using Outlook 1
S Outlook User defined date field (UDF) not syncing Using Outlook 2
I Locating an email after search - Field Chooser Using Outlook 2
Diane Poremsky Create a custom field for Outlook messages Using Outlook 0
Diane Poremsky Create a Custom Numbering Field for Outlook messages Using Outlook 0
T Uploading Outlook 2016 Contacts to Exchange Server Drops "Company" field data in 30% of records Exchange Server Administration 4
Diane Poremsky Display the Created Date field of any Outlook item Using Outlook 0
S Selecting "Mileage" field on "Detail" page Outlook VBA and Custom Forms 2
A Add attachments to appointment based on field values Outlook VBA and Custom Forms 0

Similar threads

Top