Trigger example: Remove headers

Overview

It's possible to implement custom scripts in hMailServer which are executed when certain actions occrur. This example shows you how to remove all Received-headers from a message before it is accepted.

Script

Sub OnAcceptMessage(oClient, oMessage)
   Dim oHeaders
   set oHeaders = oMessage.Headers

   EventLog.Write("Header count: " + CStr(oHeaders.Count))

   Dim i
   For i = oHeaders.Count -1 To 0 Step -1
   
      dim oHeader
      Set oHeader =oHeaders.Item(i)
   
      EventLog.Write("Header found: " + oHeader.Name)
      
      ' Check i this is a header which we should delete.
      if LCase(oHeader.Name) = "received" Then
         oHeader.Delete
         EventLog.Write("Header deleted.")
      End If
      
   Next
   
   ' Save all the changes...
   oMessage.Save
   
End Sub

Search documentation