How to obtain internet headers from Outlook

Hi,

I did not find any method to obtain the Internet Headers from a MailMessage that I have retrieved from Outlook.
I have tried both Get Outlook Mail Messages and Get Exchange Mail Messages. I need to get all the details without using the Outlook interface or saving the messages to disk (might contain malware)

Internet Headers Example
From: Media Temple user (mt.kb.user@gmail.com)
Subject: article: How to Trace a Email
Date: January 25, 2011 3:30:58 PM PDT
To: user@example.com
Return-Path: <mt.kb.user@gmail.com>
Envelope-To: user@example.com
Delivery-Date: Tue, 25 Jan 2011 15:31:01 -0700
Received: from po-out-1718.google.com ([72.14.252.155]:54907) by cl35.gs01.gridserver.com with esmtp (Exim 4.63) (envelope-from <mt.kb.user@gmail.com>) id 1KDoNH-0000f0-RL for user@example.com; Tue, 25 Jan 2011 15:31:01 -0700
Received: by po-out-1718.google.com with SMTP id y22so795146pof.4 for <user@example.com>; Tue, 25 Jan 2011 15:30:58 -0700 (PDT)
Received: by 10.141.116.17 with SMTP id t17mr3929916rvm.251.1214951458741; Tue, 25 Jan 2011 15:30:58 -0700 (PDT)
Received: by 10.140.188.3 with HTTP; Tue, 25 Jan 2011 15:30:58 -0700 (PDT)
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=+JqkmVt+sHDFIGX5jKp3oP18LQf10VQjAmZAKl1lspY=; b=F87jySDZnMayyitVxLdHcQNL073DytKRyrRh84GNsI24IRNakn0oOfrC2luliNvdea LGTk3adIrzt+N96GyMseWz8T9xE6O/sAI16db48q4Iqkd7uOiDvFsvS3CUQlNhybNw8m CH/o8eELTN0zbSbn5Trp0dkRYXhMX8FTAwrH0=
Domainkey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=wkbBj0M8NCUlboI6idKooejg0sL2ms7fDPe1tHUkR9Ht0qr5lAJX4q9PMVJeyjWalH 36n4qGLtC2euBJY070bVra8IBB9FeDEW9C35BC1vuPT5XyucCm0hulbE86+uiUTXCkaB 6ykquzQGCer7xPAcMJqVfXDkHo3H61HM9oCQM=
Message-Id: <c8f49cec0807011530k11196ad4p7cb4b9420f2ae752@mail.gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="----=_Part_3927_12044027.1214951458678"
X-Spam-Status: score=3.7 tests=DNS_FROM_RFC_POST, HTML_00_10, HTML_MESSAGE, HTML_SHORT_LENGTH version=3.1.7
X-Spam-Level: ***
Message Body: This is a KnowledgeBase article that provides information on how to find email headers and use the data to trace a email.
1 Like

Hey @c.ciprian,

The details is mostly present in mail header. You can please try the below…

Hope this helps…

Thanks
Nithin

Hi @Nithinkrishna,

This returns MailMessage object that does not contain the internet headers with the path followed by the email.

1 Like

Hey @c.ciprian

This can throw some light !

1 Like

This still implies modifications (macros) in Office, that I’m trying to avoid.

1 Like

Yep, But you may need to apply using it in UiPath.

Something like accessing mails from outlook application object, instead of going to get mail activity as it is limited to use mail message object.

#nK

1 Like

Could you help me with a sample flow?

kindly note as well and be aware of custom header fields set by the sending application:

1 Like

I am aware. But the elements available do not contain the Internet Headers :frowning:

Hi @c.ciprian ,

i did not tested, but you might need to use Invoke code, and get the desired results.
Anyway, curious if a stable / good solution exist for this.

Vasile.

This is a working example as macro in Outlook. How do I make it work in UiPath?

Sub ViewInternetHeader()
    Dim olItem As Outlook.MailItem, olMsg As Outlook.MailItem
    Dim strheader As String

    For Each olItem In Application.ActiveExplorer.Selection
        strheader = GetInetHeaders(olItem)
    
        Set olMsg = Application.CreateItem(olMailItem)
        With olMsg 
            .BodyFormat = olFormatPlain
            .Body = strheader
            .Display
        End With
    Next
    Set olMsg = Nothing
End Sub

Function GetInetHeaders(olkMsg As Outlook.MailItem) As String
    ' Purpose: Returns the internet headers of a message.'
    ' Written: 4/28/2009'
    ' Author:  BlueDevilFan'
    ' //techniclee.wordpress.com/
    ' Outlook: 2007'
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
    Dim olkPA As Outlook.PropertyAccessor
    Set olkPA = olkMsg.PropertyAccessor
    GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
    Set olkPA = Nothing
End Function
1 Like

Solution:
Using Alphabet activities convert the MailMessage to MailItem, then Invoke Code as below

Dim olkPA As Microsoft.Office.Interop.Outlook.PropertyAccessor
olkPA = MyMessage.PropertyAccessor
MyHeader = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E").ToString
olkPA = Nothing

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.