Account examples

  • Revision slug: Thunderbird/Account_examples
  • Revision title: Account examples
  • Revision id: 130282
  • Created:
  • Creator: Clarkbw
  • Is current revision? No
  • Comment 113 words added

Revision Content

{{ draft() }}

{{ tb_minversion_header("3") }}

This article provides examples on accessing and manipulating Thunderbird accounts. Account interfaces provides an overview of the related interfaces. See An overview of Thunderbird components for a general description of the Thunderbird user interface and related programmatic interfaces.

Iterate over all known accounts

var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
                        .getService(Components.interfaces.nsIMsgAccountManager);
var accounts = acctMgr.accounts;
for (var i = 0; i < accounts.Count(); i++) {
  var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
  // Do something with account
}

 

Introspect the details of particular accounts (names, parameters, etc.)

var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
.getService(Components.interfaces.nsIMsgAccountManager);
var accounts = acctMgr.accounts;
for (var i = 0; i < accounts.Count(); i++) {
var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
Application.console.log(account.key);
// account.incomingServer is an nsIMsgIncomingServer
// account.identities is an nsISupportsArray of nsIMsgIdentity objects
// you can loop through it just like acctMgr.accounts above
// account.defaultIdentity is an nsIMsgIdentity
}

Iterate over the folders in an account

 

Revision Source

<p>{{ draft() }}</p>
<p>{{ tb_minversion_header("3") }}</p>
<p>This article provides examples on accessing and manipulating Thunderbird accounts. <a class="internal" href="/en/Thunderbird/Account_interfaces" title="en/Thunderbird/Account interfaces">Account interfaces</a> provides an overview of the related interfaces. See <a class="internal" href="/En/Extensions/Thunderbird/An_overview_of_the_Thunderbird_interface" title="En/Extensions/Thunderbird/An overview of the Thunderbird interface">An overview of Thunderbird components </a>for a general description of the Thunderbird user interface and related programmatic interfaces.</p>
<h2>Iterate over all known accounts</h2>
<pre><code>var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
                        .getService(Components.interfaces.nsIMsgAccountManager);
var accounts = acctMgr.accounts;
for (var i = 0; i &lt; accounts.Count(); i++) {
  var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
  // Do something with account
}</code></pre>
<p> </p><h2>Introspect the details of particular accounts (names, parameters, etc.)</h2>
<pre><code>var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]<br>                        .getService(Components.interfaces.nsIMsgAccountManager);<br>var accounts = acctMgr.accounts;<br>for (var i = 0; i &lt; accounts.Count(); i++) {<br>  var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);<br>  Application.console.log(account.key);<br>  // account.incomingServer is an nsIMsgIncomingServer<br>  // account.identities is an nsISupportsArray of nsIMsgIdentity objects<br>  //                    you can loop through it just like acctMgr.accounts above<br>  // account.defaultIdentity is an nsIMsgIdentity<br>}</code>
</pre><h2>Iterate over the folders in an account</h2>
<p> </p>
Revert to this revision