Sample code for 30+ languages & platforms
Classic ASP

Enumerate MIME Header Field Names

See more MIME Examples

Demonstrates the Chilkat Mime.GetHeaderFieldName method, which returns the name of the header-field occurrence at a zero-based index. The only argument is the index; use NumHeaderFields for the count. Original order and casing are preserved.

Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.

Background: When you need to walk all the headers — to display them, copy them, or handle duplicates that GetHeaderField would hide — index-based access is the way. NumHeaderFields bounds the loop, and this returns each field's name in its original order and casing, which matters when the exact header sequence is significant.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

set mime = Server.CreateObject("Chilkat.Mime")
success = mime.LoadMimeFile("qa_data/message.eml")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( mime.LastErrorText) & "</pre>"
    Response.End
End If

'  Iterate the header fields by index.  NumHeaderFields gives the count; GetHeaderFieldName and
'  GetHeaderFieldValue return the name and value at each zero-based index.  Original order and
'  casing are preserved.
n = mime.NumHeaderFields
Response.Write "<pre>" & Server.HTMLEncode( "Header fields: " & n) & "</pre>"

For i = 0 To n - 1
    fieldName = mime.GetHeaderFieldName(i)
    If (mime.LastMethodSuccess = 0) Then
        Response.Write "<pre>" & Server.HTMLEncode( mime.LastErrorText) & "</pre>"
        Response.End
    End If

    Response.Write "<pre>" & Server.HTMLEncode( fieldName) & "</pre>"
Next

%>
</body>
</html>