Programatically create a account in Mozilla ThunderBird

Posted on 2009-04-16
Last Modified: 2012-05-06

   I have to create a tool that will take the gmail address and configure the account in Thunderbird . Is it possible to do that using some scripts or VB program. I have got a similar script that configures the account in outlook by entering the details in registry. Can it be done in the similar way. If  so please help me.

Thanks in advance.

Question by:Priyadarshni
    LVL 9

    Expert Comment


    And the text (in case the link dies)...

    Controlling Thunderbird actually works in exactly the same way as the way that was the basis for FirefoxADM.  The big problem is, because things have been moved around, some functionality changed, it wasnt always obvious how this was done.  Now, from this point, I am going to talk in a Windows context.  However, as far as I can tell, this should work on all platforms.
    First things first:  install Thunderbird and run it for the first time.  To follow some of the prefs, it is better if you use a cleanly built machine, but if you are doing this on your machine, with your own settings in play, be careful!  If you are using it for the first time, set it up as you would want to see it in your enterprise environment if Thunderbird was freshly installed.  The overall aim of this exercise is to take a large number of these preferences you just set up and apply them to users.  You want some to be locked, some to be default and you want them in there automagically when the user first uses Thunderbird.
    Navigate to where Thunderbird is installed.  This will usually be C:\Program Files\Mozilla Thunderbird.  The way the enterprise management works in Thunderbird goes all the way back to Netscape.  There was a hidden preference in Netscape called general.config.filename.  This preference set the location of a central configuration file.  By default, this file was a ROT 13 file.  ROT is a very simplistic byte shifting encryption.  For example, the word MARK would be NBSL at ROT 1, OCTM at ROT 2 and therefore ZNEX at ROT 13.  Fortunately, there is another setting, general.config.obscure_value which allows you to set the ROT value.  I prefer ROT 0!  Where do we put this?  Inside the greprefs directory in Mozilla Thunderbirds installation directory, create a file.  Call it adm.js.  Now, lets put these two settings in there, and call the configuration file tbirdadm.cfg (from the filename, you can see where Im going with this!):
    pref(general.config.obscure_value, 0);
    pref(general.config.filename, tbirdadm.cfg);
    We now want to get all those settings you made.  Go to your Application Data directory (for Vista users, thats in C:\Users\<username>\AppData\Roaming, XP/2000 is in C:\Documents and Settings\<username>\Application Data).  There should be a folder there called Thunderbird.  Go in there, into the Profiles directory that is below that and you should see a directory called, well, something.  Its a random name.  Inside that folder you see your profile.  The file we are interested in is prefs.js.  Open it and you will see it looks something like this:
    And here you have the settings you really want to push out to your users.  You now have to choose which settings to use.  This is the really tricky part.  There will be a LOT of trial and error at this stage - finding all the right settings can be a pain.  One gotcha with the prefs.js file is it only includes preferences where the user has preference values that are different to those Thunderbird has as default.  If you have a fresh profile as I said earlier, I suggest copy from this file all the preferences that start user_pref(mail&.  Now, in the C:\Program Files\Mozilla Thunderbird directory, create a file called tbirdadm.cfg.  Paste all the settings you had in there.  Now, replace all the user_pref in that file with lockPref (ie.  Edit, Replace) and close the file.
    Time to test!  Rename the entire Thunderbird directory from the Application Data directory to Thunderbird.bak.  Fire up Thunderbird.  You are now a first time user using Thunderbird.  Hopefully, Thunderbird will now be using your managed preferences and will automatically have configured Thunderbird to act as you want it to for a first time user.  Whats more, all the settings will be locked from being changed:
    Do not be despondent if, when you loaded Thunderbird up, you got an error, or no accounts were set up.  Close Thunderbird, delete the Thunderbird directory, go into the Thunderbird.bak directory and have another look at that prefs.js file.  You might also find that some values seem not locked.  Thunderbird is a tricksy application in that way.  Sometimes, settings arent locked or you find there are workarounds.  For example, in that screenshot above, if someone ticks and unticks that Attach this signature box, it unlocks the box.  The problem is, that tick box is not locked, because it never appeared in the prefs.js as unticked is default.  So, you tick the box, close Thunderbird, go to the prefs.js file and find this value:  user_pref(mail.identity.id1.attach_signature, true);.  Therefore, you just add:  lockPref(mail.identity.id1.attach_signature, false);  to the tbirdadm.cfg file file.  There are plenty more of these to find!
    Once you have all that working, you have one last major problem which is, some of the settings are configured to you.  For example, in mine, many of them use my username.  You now have to genericise the settings.  Fortunately, you can use getenv to get Environment Variables.  This is useful because you can change a line like:
    lockPref(mail.identity.id1.draft_folder, imap://;
    lockPref(mail.identity.id1.draft_folder, imap:// + getenv(username) +;
    Not all settings are going to be as easy as that to make generic.  Some may even require some user interaction.  Some may require some more programming in the tbirdadm.js file (remember, this is effectively inside Thunderbird, so any javascript code you put in there, Thunderbird will try to execute&).  For instance, their email address and full name may not be things you can set generically and will have to teach users to set themselves (although I think it is the case that in those two examples Thunderbird will demand these are set when you first try to send an email).
    I said earlier that you might want to set default settings as opposed to locked ones.  Simple:  find the setting in tbirdadm.cfg and change lockPref to defaultPref.
    This is a bit of a wordy skip through the process but its really quite a simple process really.

    Author Comment

    Thank you for replying..
    I went through the link, But how do i use that to create account programatically? Do i have to write into prefs.js file??

    LVL 9

    Accepted Solution

    Yes! - If you can edit the prefs.js file (while Thunderbird is closed, because it only updates prefs.js on shutdown) then you'll be able to configure it to your heart's content.  There are lots of ways to programatically change the text in prefs.js (ie. a simple batch script) because it doesn't have to be in any order.  However, you may want to try SED for windows to help?


    Author Closing Comment

    Thank you

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now