Can Thunderbird be opened and specify our user ID

Discussion of general topics about Mozilla Thunderbird
Post Reply
yodaxxx
Posts: 174
Joined: January 26th, 2006, 11:11 pm

Can Thunderbird be opened and specify our user ID

Post by yodaxxx »

Have several user IDs (email accounts) and want to open Thunderbird and specify a particular ID so that if I immediately send an email it will have the "From: userid" that I specified when opening.

Example: have email IDs of A@x.com; B@xc.com; and C@x.com and I want to send an
email from B@x.com (am not concerned about new emails that have come in at the time).

I would like to say to Cortana: Open Thunderbird B@x.com (or something like that) and have TB launch, pointing to B@x.com.

Setting a default user ID is not the answer because one time I might Open Thunderbird specifying A@x.com and the next time I might Open Thunderbird specifying C@x.com.
User avatar
DanRaisch
Moderator
Posts: 127246
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Can Thunderbird be opened and specify our user ID

Post by DanRaisch »

You could do that if you created a separate Thunderbird profile for each email account, as Thunderbird can use command line parameters to open with a specific profile. http://kb.mozillazine.org/Starting_Fire ... ed_profile.
morat
Posts: 6437
Joined: February 3rd, 2009, 6:29 pm

Re: Can Thunderbird be opened and specify our user ID

Post by morat »

You could create a command line handler with an extension.

Usage:

thunderbird.exe -select "beta@gmail.com"

Instructions:

* create tweaks.zip file (contains install.rdf, chrome.manifest, commandline.js)
* rename tweaks.zip file to tweaks.xpi
* install tweaks.xpi file

Source:

* install.rdf

Code: Select all

<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:em="http://www.mozilla.org/2004/em-rdf#">

  <Description about="urn:mozilla:install-manifest">
    <em:id>tweaks@example.com</em:id>
    <em:type>2</em:type>
    <em:unpack>true</em:unpack>
    <em:name>Tweaks</em:name>
    <em:version>1.0</em:version>
    <em:creator>morat</em:creator>
    <em:description>Personalize Thunderbird.</em:description>
    <em:homepageURL>http://forums.mozillazine.org/viewtopic.php?f=28&t=3011615</em:homepageURL>

    <!-- Thunderbird -->
    <em:targetApplication>
      <Description>
        <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
        <em:minVersion>38.0</em:minVersion>
        <em:maxVersion>99.0</em:maxVersion>
      </Description>
    </em:targetApplication>

  </Description>

</RDF>
* chrome.manifest

Code: Select all

content tweaks .
locale tweaks en-US .
skin tweaks classic/1.0 .

component {3550f703-e582-4d05-9a08-453d09bdfdc6} commandline.js
contract @mozilla.org/commandlinehandler/general-startup;1?type=tweaks {3550f703-e582-4d05-9a08-453d09bdfdc6}
category command-line-handler m-tweaks @mozilla.org/commandlinehandler/general-startup;1?type=tweaks
* commandline.js

Code: Select all

var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

function TweaksCommandLineHandler() {}

TweaksCommandLineHandler.prototype = {
  classID: Components.ID("{3550f703-e582-4d05-9a08-453d09bdfdc6}"),
  QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
  handle: function (commandLine) {
    var param = commandLine.handleFlagWithParam("select", false);
    if (param) {
      if (commandLine.state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) {
        var win = Services.ww.openWindow(null, "chrome://messenger/content/messenger.xul",
          "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar", null);
        win.addEventListener("load", function handleLoad() {
          win.removeEventListener("load", handleLoad, false);
          win.setTimeout(function () {
            var allServers = win.MailServices.accounts.allServers;
            for (var i = 0; i < allServers.length; i++) {
              var currentServer = allServers.queryElementAt(i, Components.interfaces.nsIMsgIncomingServer);
              // win.Application.console.log("Tweaks: " + currentServer.rootFolder.abbreviatedName);
              if (currentServer.rootFolder.abbreviatedName == param) {
                var inboxFolder = currentServer.rootFolder.getFolderWithFlags(Components.interfaces.nsMsgFolderFlags.Inbox);
                if (inboxFolder) {
                  // win.Application.console.log("Tweaks: " + inboxFolder.URI);
                  win.gFolderTreeView.selectFolder(inboxFolder);
                  break;
                }
              }
            }
          }, 1000);
        }, false);
      }
      if (commandLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
        var win = Services.wm.getMostRecentWindow("mail:3pane");
        var allServers = win.MailServices.accounts.allServers;
        for (var i = 0; i < allServers.length; i++) {
          var currentServer = allServers.queryElementAt(i, Components.interfaces.nsIMsgIncomingServer);
          // win.Application.console.log("Tweaks: " + currentServer.rootFolder.abbreviatedName);
          if (currentServer.rootFolder.abbreviatedName == param) {
            var inboxFolder = currentServer.rootFolder.getFolderWithFlags(Components.interfaces.nsMsgFolderFlags.Inbox);
            if (inboxFolder) {
              // win.Application.console.log("Tweaks: " + inboxFolder.URI);
              win.gFolderTreeView.selectFolder(inboxFolder);
              win.focus();
              break;
            }
          }
        }
      }
      commandLine.preventDefault = true;
    }
  },
  helpInfo: "  -select <account>  Select the inbox in a specific account.\n",
};

var NSGetFactory = XPCOMUtils.generateNSGetFactory([TweaksCommandLineHandler]);
Thunderbird 45.1.1
Windows 7 SP1 32-bit

Also,

The session.json file in the profile folder stores the selected folder uri when the application is shutdown. Perhaps, you could create an external script to change the folderURI data in the session.json file.
Last edited by morat on June 29th, 2016, 12:07 am, edited 5 times in total.
yodaxxx
Posts: 174
Joined: January 26th, 2006, 11:11 pm

Re: Can Thunderbird be opened and specify our user ID

Post by yodaxxx »

Thank you Dan for your response – I think I understand but let me recap to be sure – just to let you know, I am looking into this in order to use voice commands (i.e. voice recognition) to launch TB "mouselessly".

Using the example above – I think it means: create separate profiles for the three email accounts (profileA for A@x.com; profileB for B@x.com; and profileC for C@x.com. Then an email to be from A@x.com can be sent by saying: Open Thunderbird dashP profileA ... Is that correct? And if TB is already running for the default profile (for the combined email accounts of A; B; C) a command of Open Thunderbird dashP profilerA dashNOdashremote would be necessary.
Post Reply