Adding IMAP accounts to Thunderbird in Batches

ReboundTeam

Newbie
Joined
Sep 17, 2023
Messages
21
Reaction score
5
Hey,

My situation is as follows:
  • I have a lot of different E-Mail accounts with IMAP support, all from the same provider.
  • I need to have an eye on them but do not want to always log in and out of the web interface (I also want to do auto filers and some other stuff that doesn't work great in a web browser).
  • I need a way to add them to my Thunderbird (or any other good IMAP client) in Batches. I want to specify Login + Password + IMAP Server details and then they should just get added like you normally would add them.
  • I don't need any proxy support.
  • We are talking about 200 - 300 IMAP accounts that I would like to monitor.

My proposed solution for this would either be:
  • Find / develop a Thunderbird extension that can do it
  • Modify the Thunderbird database through a script
  • Use a different E-Mail client

Has anybody have a similar problem? Or a solution that could work without much hassle?

Thanks,
Rebound
 
You can manipulate the prefs.js file and play along with this either from Python or any other script.
Here's a draft (have not checked) that could give you an idea of how to do it.

Python:
import os
import re

# Path to Thunderbird profile directory (update this as needed)
THUNDERBIRD_PROFILE_DIR = "/path/to/thunderbird/profile"
PREFS_FILE = os.path.join(THUNDERBIRD_PROFILE_DIR, "prefs.js")

# Example IMAP account details
accounts = [
    {"email": "[email protected]", "password": "password1", "imap_server": "imap.example.com"},
    {"email": "[email protected]", "password": "password2", "imap_server": "imap.example.com"},
    # Add more accounts here
]

def add_account_to_prefs(account, prefs_file):
    email = account["email"]
    password = account["password"]
    imap_server = account["imap_server"]

    # Template for adding account configuration to prefs.js
    account_template = f"""
    user_pref("mail.account.account{email}", "imap://{email}@{imap_server}");
    user_pref("mail.accountmanager.accounts", "account{email}");
    user_pref("mail.identity.id{email}.useremail", "{email}");
    user_pref("mail.identity.id{email}.reply_on_top", 1);
    user_pref("mail.server.server{email}.hostname", "{imap_server}");
    user_pref("mail.server.server{email}.type", "imap");
    user_pref("mail.server.server{email}.userName", "{email}");
    """
    try:
        with open(prefs_file, "a") as file:
            file.write(account_template)
        print(f"Account {email} added to prefs.js.")
    except Exception as e:
        print(f"Error adding account {email}: {e}")

def main():
    if not os.path.exists(PREFS_FILE):
        print(f"prefs.js file not found at {PREFS_FILE}")
        return

    for account in accounts:
        add_account_to_prefs(account, PREFS_FILE)

    print("All accounts have been added. Restart Thunderbird to apply changes.")

if __name__ == "__main__":
    main()
 
Back
Top