Sign in to follow this  
Followers 0
Cush

Converting .eml To .txt

4 posts in this topic

Hi,

I have an App that needs to read emails that I've dragged into a folder from Outlook Express. Unfortunately, the email is an .eml

file, and my App needs a .txt file. I can only think of clunky ways to Automate this via Notepad - is there an easier way?

Thanks

Paul

Share this post


Link to post
Share on other sites



Hi,

I have an App that needs to read emails that I've dragged into a folder from Outlook Express. Unfortunately, the email is an .eml

file, and my App needs a .txt file. I can only think of clunky ways to Automate this via Notepad - is there an easier way?

Thanks

Paul

In Outlook Express you can use the Save As function to save an email as a .txt file. You could write an AutoIt script to do this.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Eml files do seem to be just txt files. OE seems to just cut down from the top to the From: line and saves from there onwards.

Here is a UDF that can do a folder of the Eml files.

; Enter folder as UDF parameter
_Eml2Txt('c:\folder')

Func _Eml2Txt($directory)
    Local $file_temp = @TempDir & '\MailConverter.txt'
    Local $file_eml, $file_temp, $handle_read
    Local $handle_search, $handle_write, $line
    FileChangeDir($directory)
    $handle_search = FileFindFirstFile('*.eml')
    If $handle_search <> -1 Then
        While 1
            $file_eml = FileFindNextFile($handle_search)
            If @error Then ExitLoop
            If $file_eml = '.' Or $file_eml = '..' Then ContinueLoop
            $handle_read = FileOpen($file_eml, 0)
            $handle_write = FileOpen($file_temp, 2)
            While 1
                $line = FileReadLine($handle_read)
                If @error Then ExitLoop
                While StringLeft($line, 5) <> 'From:'
                    ContinueLoop 2
                WEnd
                While 1
                    FileWriteLine($handle_write, $line)
                    $line = FileReadLine($handle_read)
                    If @error Then
                        FileClose($handle_write)
                        FileClose($handle_read)
                        FileMove($file_temp, StringReplace($file_eml, '.eml', '.txt'))
                        ExitLoop 2
                    EndIf
                WEnd
            WEnd
        WEnd
        FileClose($handle_search)
        FileDelete($file_temp)
    EndIf
EndFunc

It will save the txt files in the same folder.

Edit:

Localized all needed variables.

Edited by MHz

Share this post


Link to post
Share on other sites

MHz - thats just the job. Thanks very much !!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0