About 2 years ago I wrote myself a small program to back up my e-mails to my local computer. It’s a very simple commandline tool that connects to a IMAP server, downloads all messages and stores them in EML format. For a long time I did not plan to publish the program, but only wanted to run it every few days myself. In the last months I have also told some friends and colleagues about it and encountered a lot of interest. For this reason I cleaned up the source code and published it on Github.
Why use eml?
EML is a simple text format which is supported by many e-mail programs. On Windows 10, no additional software needs to be installed to view EML files. The files also contain all header information and attachments in a single file - no information is lost. Due to it’s nature as a text format most operating systems know how to read and index the content of these files. Therefore you can just use the Explorer to search inside your local mails. Thus the export as EML has some advantages over Outlook or Thunderbird data files, which are hard to restore or exchange - and can only be converted with a lot of manual effort when switching the mail client.
Execute either mailbackup.sh (MacOS / Linux) oder mailbackup.ps1 (Windows). Basic usage works like this
./mailbackup.ps1 -username <USERNAME> -password <PASSWORD>
There are several parameters that you can use to change the default behaviour:
>: This is the username that will be used to login
>: The password that will be used to login.</li>
>: Sets the hostname of the IMAP server that hosts the mailbox. This parameter is optional. If you do not specify a hostname the program will try to guess it from your username – if that contains a @ sign.
- delete: Be careful: this switch will delete all mails from server once they have been downloaded
- flatten: Default behaviour is to rebuild the folder structure of the server locally. If you use this switch no folders will be created locally and all files will be written to the output directory directly.
>: This parameter works as a filter to process messages only if they are older than the date specified. The date value is expected to be given formatted as YYYY-MM-DD.
>: This changes the directory to write the messages to.
>: Sets a new naming pattern for the message files. This pattern can include the placeholders <date>, <recipient>, <sender> and <subject>
>: Sets the port number of the IMAP server
- unencrypted: Use this to use an unencrypted connection to the server (no SSL / TLS encryption)