Access the Email Message Header

This sample creates a user defined property and adds the return path so you can see its value for each email in the folder list view.

Last modified: 2009/07/18 | Accessed: 29.234  | #73
◀ Previous sample Next sample ▶
ReplyAll ReplyAll
ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the e-mail.

This example extracts the return-path property from the message header of an incoming email, and stores the info in the custom property 'ReturnPath'. Then you can display the info in the folder view.

Please copy the code into the modul 'ThisOutlookSession'; also, the Redemption must be installed.

tip  How to add macros to Outlook
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Set Ns = Application.GetNamespace("MAPI")
  Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
  If TypeOf Item Is Outlook.MailItem Then
    ExtractDataFromMsgHeader Item
  End If
End Sub

Private Sub ExtractDataFromMsgHeader(Mail As Outlook.MailItem)
  On Error Resume Next
  Dim sfItem As Object
  Dim MsgHeader$, ReturnPath$
  Dim p1&, p2&
  Dim Prop As Outlook.UserProperty

  Set sfItem = CreateObject("redemption.safemailitem")
  sfItem.Item = Mail
  p1 = InStr(1, MsgHeader, "Return-Path:", vbTextCompare)
  If p1 Then
    p1 = p1 + Len("Return-Path:")
    p2 = InStr(p1, MsgHeader, vbCrLf)
    If p2 Then
      ReturnPath = Trim$(Mid$(MsgHeader, p1, p2 - p1))
      Set Prop = Mail.UserProperties("ReturnPath")
      If Prop Is Nothing Then
        Set Prop = Mail.UserProperties.Add("ReturnPath", olText, True)
      End If
      Prop.Value = ReturnPath
    End If
  End If
  sfItem.Item = Nothing
  Set sfItem = Nothing
End Sub
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.
email  Send a message