Thunderbird to Outlook converter

Thunderbird to Outlook Conversion – Unlimited

If you have thousands of emails that you want to convert from Thunderbird to Outlook then this is the guide for you.

By the time you are reading this post, chances are you have tried a bunch of software with no success. Maybe the emails weren’t converted properly or you were restricted to the number of emails you can convert. In this post we will go over a workaround which will allow you to convert thousands of emails (I once converted 5 700 emails in one go!)

The methodology

The idea is to use free software that is able to convert a certain amount of emails for free and then use Python to feed all your emails in batches to this program.

The guide will be divided into 5 main points:

  1. Obtain the Thunderbird mail
  2. Download the necessary software (Outlook Freeware & Python)
  3. The Python code
  4. Perform the conversion
  5. Import generated file into Outlook

Obtain the Thunderbird mail

The 1st step will be to prepare the thunderbird mail for the conversion. This is done by simply saving the mail you want to convert in a folder of choice.

Open your thunderbird app, then select all the mail that you want to convert. Once it is selected press Ctrl + S (or go to File > Save As > File…). Then select or create a folder in which you would like to save the mail. The emails will be saved as .eml files in the folder.

Download the necessary software

We will need to download 2 sets of software, unless you have them already. The 1st is Outlook Freeware (though another converted can be used as well). and the other is Python.

https://www.python.org/downloads/

Thunderbird to Outlook Python program

The program consists of 3 functions of which the 1st function navigates through the OutlookFreeware gui. It opens the program then set its window as the active window. After that it populates the program inputs then start the conversion.

def navigate_gui(src, des):
    """
    Navigates through the OutlookFreeware gui
    to supply the source and destination paths
        - src: path to the folder containing the .eml mail
        - des: path to the .pst file to be created
    """
    import pyautogui
    # Activate OutlookFreeware window
    window_name = 'OutlookFreeware'
    windows = pyautogui.getAllWindows()
    window = [w for w in windows if window_name in  w.title]
    assert len(window), f"""
    {window_name} window not found by Pyautogui.
    \nOpen windows:\n{[w.title for w in windows]}
    """
                        
    window[0].activate()

    # Enter the path to the folder containing the .eml mail
    pyautogui.press('tab')
    pyautogui.press('tab')
    pyautogui.press('tab')
    pyautogui.press('tab')
    pyautogui.write(src)

    # Enter the path to where the .pst file should be saved
    pyautogui.press('tab')
    pyautogui.press('tab')
    pyautogui.write(des)

    # Run the converter
    pyautogui.press('tab')
    pyautogui.press('tab')
    pyautogui.press('tab')
    pyautogui.press('tab')
    pyautogui.press('enter')

The 2nd function handles the conversion process. It starts the conversion process then waits for the process the finish. Once the conversion is completed, the process is terminated.

def convert(src, des, exe):
    """
    Opens the Thunderbird to Outlook converter
    and starts the conversion process.
        - src: folder path where .eml files are located.
        - exe: path to the converter.
    """
    import subprocess
    import time
    import win32com.client
    from pathlib import Path
    pst = Path(des).stem
    
    # Open the converter
    process = subprocess.Popen(exe)
    time.sleep(2)

    outlook = win32com.client.Dispatch("Outlook.Application")\
                        .GetNamespace("MAPI")

    navigate_gui(src, des)

    while not pst in outlook.Folders.GetLast().Name:
        time.sleep(0.5)
    
    while pst in outlook.Folders.GetLast().Name:
        time.sleep(0.5)
    
    process.terminate()

Thunderbird to Outlook main function

Finally the main function, which addresses the conversion limit of the converter. This is done by converting the mail from the source folder in batches of 100.

def eml2pst(src, exe):
    """
    Converts Thunderbird mail to Outlook mail.
        - src: folder path in which the .eml files are.
        - exe: path to the converter.
    """
    import os
    from shutil import rmtree, copy2

    files = os.listdir(src)

    tmp = src + '/tmp/'
    des = src + '/0-converted.pst'
    
    # Convert files in batches of 100
    cnt = 0
    n = 100
    for file in files:
        if not file.endswith('.eml'):
            continue
        
        # Create a fresh directory for each batch of 100
        if cnt == 0:
            if os.path.exists(tmp):
                rmtree(tmp)
            os.makedirs(tmp)
        
        copy2(src + '/' + file, tmp)

        cnt += 1
        
        # Convert files once directory contains 100 files
        if cnt == n:
            convert(tmp, des, exe)
            cnt = 0
        
        
    if cnt:
        convert(tmp, des, exe)

Running the Thunderbird to Outlook conversion

exe = r"C:\Users\mechanicalcoder\AppData\Local\OutlookFreeware.com\Executor.exe"
src = r"C:\Users\mechanicalcoder\Documents\Thunderbird_Mail"
eml2pst(src, exe)

Import the mail into Outlook

In Outlook, select the folder where you want to import the mail to, then go to File > Open & Export > Import/Export. The import wizard will appear upon which you should follow the steps depicted below.

In step 5 select the generated .pst file, located in the source folder, in which the .eml files were located.

Future considerations

The method above is a quick solution to convert an unlimited amount of emails for free. one big downside of the current method is that it cannot function in the background. Another is that it uses third party software. These are, however, challenges to be resolved at a later stage.

For some more useful guides simply follow the link below:

https://mechanicalcoder.com/

Leave a Reply