Read headers from .eml on disk

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
cblaze22
Normal user
Normal user
Posts: 165
Joined: 2011-08-30 20:16

Read headers from .eml on disk

Post by cblaze22 » 2019-05-08 14:00

How can I load a .eml from disk and read the headers of it? I am trying to do this in the OnDeliverMessage method.

User avatar
mattg
Moderator
Moderator
Posts: 19906
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Read headers from .eml on disk

Post by mattg » 2019-05-08 14:04

Try this

Code: Select all

	For i = 1 To oMessage.Headers.Count 
		txt = "Message Subject is: " & oMessage.Subject & "   Header #" & i & " name is: " & oMessage.Headers.Item(i-1).Name
		txt = txt & " value is: " & oMessage.Headers.Item(i-1).Value
		EventLog.write txt
	Next 'i
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 3155
Joined: 2006-08-21 15:38
Location: Denmark

Re: Read headers from .eml on disk

Post by SorenR » 2019-05-08 14:23

mattg wrote:
2019-05-08 14:04
Try this

Code: Select all

	For i = 1 To oMessage.Headers.Count 
		txt = "Message Subject is: " & oMessage.Subject & "   Header #" & i & " name is: " & oMessage.Headers.Item(i-1).Name
		txt = txt & " value is: " & oMessage.Headers.Item(i-1).Value
		EventLog.write txt
	Next 'i
That's not what he want...

He want us to write the code to read the eml file (from oApp.status.UndeliveredMessages) from .\hmailserver\data so that he can prioritize his emails...

I think you should merge ALL of his posts regarding this topic into one new thread and if he keeps creating new threads ... a mild BAN might be in order. He's all over the forum.

Fellow says he's a programmer and yet he is still clueless despite us trying to explain how ends meet inside hMailServer.

Oh and cblaze22... OnDeliverMessage is NOT a method... It's a TRIGGER

Actions handled by OnDeliverMessage based from the list (oApp.status.UndeliveredMessages) will affect all BUT THE ACTUAL message. When OnDeliverMessage is triggered the message triggering OnDeliverMessage is NOT YET in the queue. So, the functionality will always be one message behind the current.
SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

cblaze22
Normal user
Normal user
Posts: 165
Joined: 2011-08-30 20:16

Re: Read headers from .eml on disk

Post by cblaze22 » 2019-05-08 15:09

This is a totally seperate question. If someone else wants to do a read of a file from disk and read the header, this email will come up. This is not being all over the place, but a distinct question. Yes I will take this answer and merge it into the other code we are working on. However, this question should be taken in context as distinct and could help someone in the future.

"Fellow says he's a programmer and yet he is still clueless despite us trying to explain how ends meet inside hMailServer." makes no sense. Being a programmer doesnt follow necessarily you know how a program works off hand or can read between the lines on incomplete documentation. Come on man. Also a TRIGGER in a broad sense is a METHOD, geez.

I know OnDeliverMessage does that, did I say otherwise? Please stick to our thread, this one is about reading a file from disk and reviewing the headers. You are the one all over the place and I believe a mild ban should be put in place.

User avatar
SorenR
Senior user
Senior user
Posts: 3155
Joined: 2006-08-21 15:38
Location: Denmark

Re: Read headers from .eml on disk

Post by SorenR » 2019-05-08 15:53

Well... I'm a genius...

Code: Select all

Dim a, b, i, Match, Matches, Done, oMail

Dim oApp : Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", "BIG SECRET")

Done = False
Do Until Done
   '
   '   List all messages in queue
   '
   Matches = Split(oApp.status.UndeliveredMessages, vbNewLine)
   For Each Match in Matches
      WScript.Echo "**********"
      WScript.Echo Match
      WScript.Echo ""
      
      '
      '   Fields are TAB delimited
      '
      b = Split(Match, vbTab)
      WScript.Echo "**********"
      For Each a in b
         WScript.Echo a
      Next
      WScript.Echo ""

      '
      '   Create dummy message to hold current queued message
      '
      Set oMail = CreateObject("hMailServer.Message")

      '
      '   Copy queued message into dummy message and reload
      '
      strFilename = oMail.Filename
      With CreateObject("Scripting.FileSystemObject")
         .CopyFile b(5), strFilename, True
      End With
      oMail.RefreshContent

      '
      '   Voila! List all headers
      '
      WScript.Echo "**********"
      For i = 0 To oMail.Headers.Count-1
         WScript.Echo Right("0" & i, 2) & " " & oMail.Headers(i).Name & ": " & oMail.Headers(i).Value
      Next
      WScript.Echo ""

      '
      '   !!! WARNING !!! DO NOT SAVE MESSAGE !!!
      '
      '   oMail.Save
      Set oMail = Nothing
   Next
   WScript.Sleep(1000)
   Done = True
Loop

WScript.Quit 0

Code runs in a CMD window on the server.
SørenR.

The quantum rule of insecurity which states that the act of observing how vulnerable a host or service is changes the insecurity level of the service.

cblaze22
Normal user
Normal user
Posts: 165
Joined: 2011-08-30 20:16

Re: Read headers from .eml on disk

Post by cblaze22 » 2019-05-08 16:21

Yes you certainly are. Lets continue this in our main thread on this, this handles the reading headers from file on disk

Post Reply