How to Recover Emails from Postfix Server, Dovecot, and Thunderbird Mail Client

In this article we’ll discuss how to recover email files from a Postfix mail server with Dovecot, how to back up emails and restore lost emails, and how to transfer emails to a new server or another client machine.

How to Recover Emails from Postfix Server, Dovecot, and Thunderbird Mail Client

Backup is an important part of the activity performed to maintain the server and the entire domain. Since the server is a crucial part of your network, make sure your backup your data regularly. If something goes wrong – for example, certain equipment breaks down – you will be able to restore the server’s operability using a backup copy. However, the problem in question is this: what can you do when there is no backup file, or when it’s impossible to restore the server from it? In this case, a special data recovery tool – Hetman Partition Recovery – is going to save you. With its help, you’ll be able to recover the lost emails from your server.

We will explore in detail how to back up your files and then recover data on a client machine, with the example of Thunderbird mail client in a Linux operating system, and how to restore emails on a server after reinstalling or formatting the hard disk – or even transfer all emails to a new server. For starters, let’s explore why you can lose access to your emails.

Go to view
How to Install and Configure a Postfix Mail Server with Dovecot on Linux Ubuntu

How to Install and Configure a Postfix Mail Server with Dovecot on Linux Ubuntu

Why emails can be lost

The causes behind the loss of emails can be extremely varied. However, the main factors are these:

  • Accidental removal of a user’s folder on the client machine;
  • Server failures;
  • Mail server breakdowns;
  • Incorrect administration;
  • Loss of access to the mailbox;
  • Or erasing important data in case of reinstalling the operating system or accidentally formatting the hard disk.
Go to view
How to Recover Emails from Postfix Server, Dovecot, and Thunderbird Mail Client

How to Recover Emails from Postfix Server, Dovecot, and Thunderbird Mail Client

Thunderbird user backup folder

Before you start looking for the lost data, you need to decide where email files can be found.

As we know, all emails that reach the server are written to a certain directory and stored until they are removed. Emails are deleted from the server when you remove them from your mailbox trash folder. When a mail client is used on a client machine, the messages are stored both on the server and on the client machine where the corresponding mail client is used.

For illustration, I’ll show you where user data files are stored in case of Thunderbird mail client, how to back them up, and how to recover them.

In a Linux operating system, Mozilla Thunderbird mail client keeps all user settings, passwords, addresses and email files on the user’s client machine. When the application is launched for the first time, it creates a default directory with a path like this:

Home/username/.thunderbird/

directory for /.thunderbird

This folder is hidden so you can only view its contents in the mail client window - or you can change the settings to make hidden folders visible. Click on the Menu button and check the box for the option Show Hidden Files.

Show hidden files

To open this folder, click Menu in the application windows, go to HelpTroubleshooting Information, and in the tab that opens, find the line Profile Directory and click on Open Directory. This will open the user folder in the Explorer window. In this folder, you can find the subfolders for calendar, settings, mail and so on.

Menu - Help - Troubleshooting Information - Profile Directory

Mozilla Thunderbird has no built-in tools for creating a backup copy of profile data or user’s correspondence files. That is why if you need to transfer a user profile to another computer or if your computer (or its operating system) fails for some reason, there are two variants - to use third-party software or create a profile backup manually.

To back up data, go several levels up and copy the .thunderbird folder to another drive.

Back up data - .thunderbird

A folder with a randomly generated name is created for every user. To transfer data to another computer you will have to copy the contents of this directory to the same folder but on the new computer.

How to recover data from backup

To recover data from backup of transfer it to another PC, install and run Thunderbird on the new computer. When launched for the first time, the application will create a new user folder with the path I have shown before. Close the program without changing its settings.

First launch of Thunderbird apps

Follow the path to the profile folder and replace its contents with the files from the backup. When the operating system asks you about replacing the files, choose Replace.

Transferring files from a backup

After you launch the program again, you will sign in to the old user profile and you will see all the emails that existed at the time when the backup was created.

All emails have been uploaded into the app

How to recover user data from a client machine after removal or formatting

If you accidentally removed a user from a client machine, the server is out of order, and you have no backup to rely on, use Hetman Partition Recovery to bring the data back.

The tool recovers data from any devices, regardless of the cause of data loss.

In case of a server running on a Linux operating system, you need to connect the hard disk to a Windows computer. When you start the program, it will display all hard disks connected to this computer. In the window that opens, right-click on the disk where the mail client user data was stored and select Open. After that, choose the scan type - Fast scan or Full analysis.

Disk scan

Run a fast scan first - it will take less time. If the program can’t find the missing files, then go for Full analysis, select the file system and click Next. When the scan is complete, follow the path to the directory containing user files, select that folder and click Recovery; choose where to save the data, the hard disk and folder, and hit Recovery again.

Recovering a directory with mailbox data

After that, the last step is to replace the new user files with the old items like I have shown before. When you do it, you will see all recovered messages in your Inbox folder.

If the program failed to restore access to the user profile and the messages are still inaccessible, you can view them in a text editor.

To do it, open the inbox file. Follow this path:

home/user name/.thunderbird/user directory/mail/mail.hetmansoftware.com

Open the inbox file in a text editor

File– Inbox. It contains all emails that were delivered to your mailbox. This way, you’ll be able to receive a necessary email or view the contents of an important message. If this recovery method doesn’t work, try recovering data from the server.

Postfix+Dovecot mail backup

In one of the previous articles, we have already told you about installing and configuring a Postfix server with Dovecot, and where to find email files.

Depending on the type of storage method applied, such files can be stored in the folder with the name var/mail and the user name, if mbox is used.

Data stored in var/mail

Alternatively, they can be stored in the folder with the name maildir, if this type of storage method is used. The upper level of Maildir directory contains such folders as Maildir/cur, Maildir/new and Maildir/tmp.

User data directory - maildir

When an email is delivered, it is placed into a file stored inside the tmp subdirectory. The file name is formed with the use of current time, host name, process identifier for the process that created this file, and a random digit - all of these to ensure that all file names are unique.

Email file name in the folder cur

After the email is written to the file, a link to it is created in the new directory, while the current link is removed from the tmpdirectory.

When the mail client find a message in the new folder, it moves them to the cur folder (with the help of rename(), because otherwise it may result in creating duplicates), while adding informative suffixes to their names. An informative suffix contains a colon (to separate the unique file name and the current information), the digit 2, a comma and various flags. This specific digit - 2 - indicates the version of the information given after the comma. The specification determines the flags used to indicate if the message was read, deleted and so on, and they use the first letters of the following words: Passed, Replied, Seen, Trashed, Draft and Flagged.

So new emails are sent to the new folder, and after they are read, they are passed to the cur folder by renaming them and adding a suffix.

To back up mail files, open the directory for a specific user and copy the message files to another disk.

Backing up the folder cur

How to recover emails from backup

To recover emails from a backup you need to transfer the email files from the backup to the new folder following this path – home/user name/Maildir/new.

Transferring email files from backup to new folder

Immediately after the transfer, you won’t see the messages in the client window, since some changes must be made before it’s possible. To have the files displayed in the mail client, you need to edit their names.

Right-click on a file and choose Rename. Now remove all characters after the domain name of your server. In my case, they are :2,S (colon - two - s).

Edit email file names

After that, open the mail client and click Get Messages. After that all the emails that were transferred from backup will appear on the inbox list with the unread status.

Uploading emails from backup

This way, you can use files from backup to recover an accidentally deleted email, or transfer emails to the new server.

How to recover email files with Hetman Partition Recovery

If the server breaks down, a user is deleted accidentally, the hard disk is formatted, the operating system is reinstalled, or email files are lost while there is no backup, they can still be restored with the help of Hetman Partition Recovery.

If your server is running on a Linux operating system, you need to take the hard disk out of the server and connect it to a Windows computer. Then start the program and scan the connected disk. After that, follow the path where the email files were stored, select the directory or its contents and click Recovery. Then change the disk and folder where the files should be saved, and click Recovery one more time.

Recovering the cur directory

When saving them, the program will ask you to change file names since they contain a colon which is not supported as a filename element by some operating systems, including Windows. In this case, there is nothing to worry about: in the end, the files will be renamed anyway when copied to the server, and those characters will be removed. Check the box next to Replace all unknown symbols to and click to rename them.

Renaming files when saving them

After the recovery, the folder will contain email files, and then you can transfer them to a new server.

Before copying the files, the server should be configured, and a user with the same name should be created. Copy the files to the new folder and edit the names as I have shown before - by removing the suffixes containing several characters – *_2,S. After that, open the mail client and check the mail, then click here to get messages. We have recovered all messages.

Conclusion

If for some reason a user permanently loses access to their Thunderbird profile (or their profile in any other mail client), the contents of such files can be viewed in a text editor. As you open it, you’ll see the original email contents, including the sender’s and recipient’s email addresses, text and other data. This way, you’ll be able to retrieve the required information from the recovered emails.

Vladimir Artiukh

Author: , Technical Writer

Vladimir Artiukh is a technical writer for Hetman Software, as well as the voice and face of their English-speaking YouTube channel, Hetman Software: Data Recovery for Windows. He handles tutorials, how-tos, and detailed reviews on how the company’s tools work with all kinds of data storage devices.

Oleg Afonin

Editor: , Technical Writer

Oleg Afonin is an expert in mobile forensics, data recovery and computer systems. He often attends large data security conferences, and writes several blogs for such resources as xaker.ru, Elcomsoft and Habr. In addition to his online activities, Oleg’s articles are also published in professional magazines. Also, Oleg Afonin is the co-author of a well-known book, Mobile Forensics - Advanced Investigative Strategies.

Recommended For You

Hello! This is AI-based Hetman Software virtual assistant, and it will answer any of your questions right away.
Start Chat