(VBScript) Iterate Email Headers
Demonstrates how to iterate over the email header fields.
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Email")
set email = CreateObject("Chilkat.Email")
' First, load an email from a file.
' Note: an email object may be loaded from a file, or
' downloaded directly from a POP3 or IMAP server...
success = email.LoadEml("testReceivedHdrs.eml")
If (success <> 1) Then
outFile.WriteLine(email.LastErrorText)
WScript.Quit
End If
' How many header fields?
n = email.NumHeaderFields
If (n > 0) Then
' Display the name and value of each header:
For i = 0 To n - 1
name = email.GetHeaderFieldName(i)
value = email.GetHeaderFieldValue(i)
outFile.WriteLine(i)
outFile.WriteLine(name)
outFile.WriteLine(value)
Next
End If
outFile.Close
|