Get to: from internet Header

Status
Not open for further replies.

oliv-

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi,
I would like to programmatically identify the email address on which i received this email.
Knowing that I have an account EXCHANGE, with aliases.

To do this manually you must open the email and click on File / properties and search "to:" in internet HEADER.

I need this to stop newsletters.

Note that this property does not give the right information :
Const PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
 
Code:
Function GetToFromHeader(objMail As Outlook.MailItem) As String
'---------------------------------------------------------------------------------------
' Procedure : GetToFromHeader
' Author    : OLIV- from original code brettdj
' Date      : 04/06/2015
' Purpose   :
'---------------------------------------------------------------------------------------
'
    Dim objRegex As Object
    Dim objRegM As Object
    Dim MailHeader As String
    Dim ExtractText As String
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001F"
    MailHeader = objMail.PropertyAccessor.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)

    Set objRegex = CreateObject("vbscript.regexp")
    With objRegex
        .ignorecase = True
        .Pattern = "To:.*<(.+)>"
        If .test(MailHeader) Then
            Set objRegM = .Execute(MailHeader)
            GetToFromHeader = objRegM(0).submatches(0)
        Else
            GetToFromHeader = "No match"
        End If
    End With
End Function
 
best with this code
Code:
Function GetToFromHeader(objMail As Outlook.MailItem) As String
'---------------------------------------------------------------------------------------
' Procedure : GetToFromHeader
' Author    : OLIV- from original code brettdj
' Date      : 04/06/2015
' Purpose   :
'---------------------------------------------------------------------------------------
'
    Dim objRegex As Object
    Dim objRegM As Object
    Dim MailHeader As String
    Dim ExtractText As String
    Dim i
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001F"
    MailHeader = objMail.PropertyAccessor.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)

    Set objRegex = CreateObject("vbscript.regexp")
    With objRegex
        .ignorecase = True
        .Pattern = "(\n)To:.*<(.+)>"
        If .test(MailHeader) Then
            Set objRegM = .Execute(MailHeader)
            For i = 0 To objRegM(0).submatches.Count - 1
            If InStr(1, objRegM(0).submatches(i), "@", vbTextCompare) Then
            GetToFromHeader = objRegM(0).submatches(i)
            Exit For
            End If
            Next i
        Else
            GetToFromHeader = "No match"
        End If
    End With
End Function
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Convert Subject Line to Internet Header version of Subject Outlook VBA and Custom Forms 10
O No Internet Header Properties Using Outlook 2
G Creating an Outlook Rule using Internet Header time Using Outlook 1
Graham Hyman Outlook 2016 Internet Calendars appearing as deleted Using Outlook 4
K Can VBA intervene when updating Internet Calendars? Outlook VBA and Custom Forms 5
B How to get ALL Internet headers in Outlook desktop? Using Outlook 1
Diane Poremsky Internet Mail Issues with Outlook Using Outlook 0
Diane Poremsky Publishing Calendars on the Internet or an Intranet Using Outlook 0
Diane Poremsky How to View Internet Headers Using Outlook 0
M Reminders or Notifications for Internet Calendars Using Outlook 1
Diane Poremsky Sharing Outlook Calendar and Contacts over the Internet Using Outlook 0
R Using Internet Calendar in Outlook 2007 within Citrix Using Outlook 1
M Sharing of BCM database across the internet BCM (Business Contact Manager) 2
J Emails in outlook and internet history logging Using Outlook 1
D Deleting internet calendar on one computer removes it from all computers Using Outlook 2
A webinar.ics is not a valid Internet Calendar file Using Outlook 1
M Time Zone Problems with Internet Calendar Using Outlook 20
M How to set exchange calendar as default when combining with Internet calendar Using Outlook 2
K message.vcs is not a valid Internet calendar file !! Exchange Server Administration 5
S possible to access my PST file on the Internet Using Outlook 2
J Internet images embed when pasted in Outlook 2010 Using Outlook 0
T Error when updating Internet Calendar Subscriptions Using Outlook 12
D Internet Calendar Subscriptions.pst bloating file size.... Using Outlook 2
I Exchange 2010 Receives But Does Not Send Email To Internet Exchange Server Administration 35
R Why Internet headers empty? Exchange Server Administration 2
B Synchronise With Internet Calendar Using Outlook.com accounts in Outlook 6
J RE: Internet Faxing with Outlook 2007 BCM (Business Contact Manager) 1
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
V Auto-Submitted: auto-replied in header Using Outlook 0
A Check for words in subject header before sending email Outlook VBA and Custom Forms 4
B Change font of reminder of an email header Outlook VBA and Custom Forms 3
K How to find specific header and copy the mail body Using Outlook 0
C Outlook Attachment List in Reply Header Using Outlook 3
J Identifying Portable Devices in Outlook Header Using Outlook 3
D Outlook 2007 e-mail header- How to set font & font size in received message headers ? Using Outlook 2
S How can I Customize Message Header in both Reading Pane and Open Message Design? Using Outlook 1
C How to copy same text header to multiple emails with custom text column Using Outlook 10
R Coming from Thunderbird: "Always prefer display name over message header" Using Outlook 1
A change the "no date" header in todo bar Using Outlook 2
T Column Header Keyboard Shortcut Available? Using Outlook 5
I How to add image header to email Using Outlook 2
E Outllook 2010 Header Image Using Outlook 3
B Need help adding an image next to the Month Name in the header. Using Outlook 1
P Email Header/People pane/contact card - GAL photo vs. contact photo Using Outlook 7
C Custom Form that allows a single SMTP header to be parsed to Field Chooser? Using Outlook 4
M IMAP header/content mismatch! Using Outlook 4
R Header not printing in Outlook 2010 Using Outlook 3
J Header information missing in one account only Using Outlook 10
T Header instead of just a signature for a disclaimer Using Outlook 1

Similar threads

Back
Top