Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA

Status
Not open for further replies.

Bruce Johnson

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
I am needing to get the email address that someone sent an email TO.
I have come up with one method that seems to use a link but that link is no longer valid:
Code:
  Const PR_SMTP_ADDRESS As String ="https://schemas.microsoft.com/mapi/proptag/0x39FE001E"
But I cannot find another way.

My immediate goal is to have a msgbox pop up with the email or the "friendly name" of the address the email was SENT to when I hit the REPLY ALL

Thanks!
Bruce
 
Last edited by a moderator:

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I created the macros below from the macros on these two pages-
VBA Sample: Do Something When Reply is Clicked
Read MAPI properties not exposed in Outlook's Object Model

It displays the received by name (account name).

Code:
Option Explicit
Private WithEvents oExpl As Explorer
Private WithEvents oItem As MailItem
Private bDiscardEvents As Boolean
   Dim oResponse As MailItem
 
Private Sub Application_Startup()
   Set oExpl = Application.ActiveExplorer
   bDiscardEvents = False
End Sub
 
Private Sub oExpl_SelectionChange()
   On Error Resume Next
   Set oItem = oExpl.Selection.Item(1)
End Sub
 
' Reply
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
   Cancel = True
   bDiscardEvents = True

Set oResponse = oItem.Reply
 afterReply
End Sub

' Forward
Private Sub oItem_Forward(ByVal Response As Object, Cancel As Boolean)
   Cancel = True
   bDiscardEvents = True

Set oResponse = oItem.Forward
 afterReply
End Sub

' Reply all
Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
   Cancel = True
   bDiscardEvents = True

Set oResponse = oItem.ReplyAll
 afterReply
End Sub

Private Sub afterReply()

Dim propertyAccessor As Outlook.propertyAccessor
Set propertyAccessor = oItem.propertyAccessor
Dim strPA As String
'PR_RECEIVED_BY_NAME
   strPA = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0040001E")
    oResponse.Display
  
MsgBox strPA

End Sub
 

Bruce Johnson

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Diane, thank so much! When it works, it is what I want (I can then build ifs or case statements once I find the results that I am looking for!) But, the issue is it seems that it will only work once or twice (or sometimes not at all) and then to get it to work, I need to restart outlook (And then is it may or may not work still...)
I have even put debug stops at the beginning of the
oItem_Reply
oItem_ReplyAll
afterReply
and it is not stoppong.
I am using 2013, and it does seem the REPLY and reply to ALL from the READING PANE is not supported, but I am hitting reply and reply all from the TOP menu (and sometimes it work and sometimes it does not)
At this point, I have your code and NO other in the ThisOutlooksession and it is NOT MODIFIED (anymore).

Any ideas?

Thanks! Bruce
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
REPLY and reply to ALL from the READING PANE is not supported,
I'll have to double check - i know it only works if the window pops out, but i thought it popped it out.

If something errors, it will stop working until you restart outlook or click Run when the cursor is it the application start up macro.

I have one that dies when it hits an error and use this attached to a ribbon button to restart it. Or to restart it anytime i think its might not be working. :)
Code:
Sub RunStart()
 Call Application_Startup
 MsgBox "App Start Started"
End Sub
 
Status
Not open for further replies.
Top