Importing .eml email to Maildir

Recently, while reconciling my company accounts, I found I was missing an email receipt. I was able to retrieve a copy of the email as a .eml file, but to store it with my other emails I needed some way to import it into my email system.

I currently store my emails on a server running Ubuntu. Locally I use a Maildir format folder and serve it to my other client machines using IMAP with the Dovecot program. On the server I use the getmail program to collect my email from several different Internet mail servers and send them to my Maildir folder. The server does this automatically for me at regular intervals as I set them up as cron tasks.

How can I get a .eml file into my system?

One approach uses the Thunderbird email client program. This program recognises the .eml file so, to import it to any email folder, you can just drag and drop the file. Since I use Thunderbird on my Windows machine as a client to my IMAP folders this allows me to store the email on my server too.

But, on my Ubuntu machines, I tend to use the Evolution email client, as that’s currently the default program for email. Unfortunately, Evolution doesn’t understand the .eml file format in the way that Thunderbird does. However, the getmail package also comes with the program getmail_maildir. Here’s how to use it to import an email into a local Maildir format folder from a terminal or shell:

getmail_maildir ~/Maildir/ < email_file.eml

  • getmail_maildir is the name of the program.
  • ~/Maildir/ is the location of the Maildir format folders:
    • the ~ is a shortcut that means the current user’s home directory.
    • the trailing / is required.
  • The < tells it to pipe the contents of the following file into the program.
  • email_file.eml is the file you want to import

7 Replies to “Importing .eml email to Maildir”

  1. Hello Rohieb, thanks for the link. I haven’t done anything with Maildir for a while as I’ve moved all my work email to gmail. Lazy, I know. I really should look again at getting free of the Google ecosystem sometime soon.

  2. For some reason getmail_maildir did not do the thing for me, and complained about missing permissions and ownership of the maildir, even though they looked correct.

    I ended up using mdeliver from the mblaze package (https://github.com/chneukirchen/mblaze), which has the same command line syntax.

  3. This has been really helpful, many thanks! Is there a way to batch process thousands of emails using this? I cannot seem to get the syntax right. I’ve tried “getmail_maildir ~/Maildir/ < *.eml", but this causes an error. I'm using macOS terminal.

  4. When I import the files. Eml the timestamp of the email is wrong. The timestamp of the email is that the actual time and not that of the original email.
    Do you have any solution to remedy the problem ?

  5. This blog is obviously interesting and informative. I have found helluva handy advices out of this amazing blog. I’d love to come back over and over again. Thanks a lot!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.