Copy .eml file to another local folder

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
New user
New user
Posts: 2
Joined: 2015-03-27 00:03

Copy .eml file to another local folder

Post by wolfmon » 2015-03-27 00:51

I am using hMail 5.4 with 3 different incoming Domains ie. and each of these are working properly.

I want to move the actual .eml files out of the hMail folder structure to a local drive folder like this. c:\a-luke\inbox\ c:\b-mary\inbox\ and c:\c-stacey\inbox\ respective of the email domains. I want to retain the complete email headers, form, body, dates, times, sender, receiver, subject, attachments, meta the whole things

I do not what to copy from one IMAP folder to another IMAP folder, This is the actual .eml file. I would be ok with using the actual hMail server folders but structure but I need all of the emails of each domain or account in the same root folder, not the sub folders that are created per email received, from what I have read this is not possible with the hMail program since an earlier version.

After the .eml file is copied I would like to delete the hMail .eml file from the system.

I have set up SMTP Routes for each associated Domains to route associated Domain emails but this does not move the emails properly.
I have thought that a rule could be used to match the incoming email but I have not been able to find anything that could do this.
If the forum holds true someone will say ' just write a script' yes that would be a great idea..problem is I have spent hours on that very subject with no success which is why I am pulling over and asking for directions. ugh.... :shock:

I want to do this because I have another program that data mines email files. the data mining program can only read from a single folder level. (c:\luke\data\inbox) and each domain needs their own single folder level.


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

Re: Copy .eml file to another local folder

Post by mattg » 2015-03-27 02:01

wolfmon wrote:I want to do this because I have another program that data mines email files. the data mining program can only read from a single folder level. (c:\luke\data\inbox) and each domain needs their own single folder level.
Sounds like that may well be illegal in some jurisdictions... (you should check your local privacy laws)

You can access the messages as they are delivered with a script.
From the script you could save to a known folder (based on domain and account if you like)
You can then delete the original message in your script, or from within an account level rule.

This is certainly possible.

How is your VBS??
Just 'cause I link to a page and say little else doesn't mean I am not being nice.

User avatar
Posts: 8849
Joined: 2011-09-08 17:48

Re: Copy .eml file to another local folder

Post by jimimaseye » 2015-03-27 11:37

Are these emails that you want to copy just one way (ie, INBOUND) that never get replied to? If so then it would be feasible to assume that all .EML files that exist in each account sub folder (in the data directory) would be incoming emails only. So it could be as simple as run an OS level copy command (use robocopy) of all .EMLs that arrive.

Of course, if these original INBOUND emails get replied to as well then you cant do this because those SENT emails will also have .EL physical files that will end up in the same account subfolders.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs :

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

Re: Copy .eml file to another local folder

Post by SorenR » 2015-03-27 12:24


<insert: "it's NOT my fault, no matter what happens" disclaimer here> :mrgreen:

Script will copy all emails in IMAP folder "INBOX" from all accounts belonging to the domains listed in the "DomainList" array to their respective directories (C:\<domain>\INBOX) and optionally delete the messages from the mailserver. Required directories on C: must be created prior to running the script or else the script will fail.

Code: Select all

Option Explicit

   Dim oApp, oDomain, oAccounts, oMessage, oMessages
   Dim i, j, Domain, DomainList : DomainList = Array("","","")

   Set oApp = CreateObject("hMailServer.Application")
   Call oApp.Authenticate("Administrator", "** Very Secret **")

   For Each Domain in DomainList

      Set oDomain = oApp.Domains.ItemByName(Domain)
      Set oAccounts = oDomain.Accounts
      For i = 0 To oAccounts.Count - 1

         Set oMessages = oAccounts.Item(i).IMAPFolders.ItemByName("INBOX").Messages
         For j = 0 to oMessages.Count - 1

            Set oMessage = oMessages.Item(j)
            With CreateObject("Scripting.FileSystemObject")
               .CopyFile Chr(34) & oMessage.FileName & Chr(34), Chr(34) & "C:\" & Domain & "\INBOX\" & Chr(34)
            End With

            ' Call oMessages.DeleteByDBID(oMessage.ID)




Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

Post Reply