kenjiro jaucian
kenjiro jaucian

Reputation: 451

Thunderbird 78+:Undefined Components.classes in thunderbird addon

Good day, I am working on a mozilla thunderbird addon and would like to make use of the components class. I know the current version of thunderbird is now 78+ so instead of XUL, I should be using HTML then from there make use of javascripts along with web extension APIs. I know i need to usensIMsgAccountManager to get the emails but I can`t make it work in javascript. I always get the error TypeError : Components.classes is undefined can someone help me? my javascript is below.

function populateAccounts() {
 var emails;
   try {
   var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
   var accounts = acctMgr.accounts;
     if (accounts.queryElementAt) {
       // Gecko 17+
       for (var i = 0; i < accounts.length; i++) {
         var account = accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount);
         emails += account.key;
       }
     } else {
       // Gecko < 17
       for (var i = 0; i < accounts.Count(); i++) {
         var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
         emails += account.key;
       }
     }
   } catch (e) {
   console.log(e);
   emails = e;
   }
 return emails;
 }

Upvotes: 0

Views: 641

Answers (1)

kenjiro jaucian
kenjiro jaucian

Reputation: 451

*Support for extensions using XUL/XPCOM or the Add-on SDK was removed in Firefox 57, released November 2017.Add-ons using the techniques described in this document are considered a legacy technology in Firefox. Don't use these techniques to develop new add-ons. Use WebExtensions instead. * nsIMsgAccountManager is an XPCOM object so it is no longer support in Thunderbird 78, instead of using XPCOM objects WebExtensions APIs should be used. There is a webextension API called accounts which returns a promise that can be used to get information for the user`s account including email.

For more info about XPCOM please open the link below

https://developer.mozilla.org/en-US/docs/Archive/Mozilla/XUL/Tutorial/XPCOM_Interfaces

Fore more info about Thunderbird Web Extensions API please open the link below

https://developer.thunderbird.net/add-ons/mailextensions

https://thunderbird-webextensions.readthedocs.io/en/78/

Fore more info about Promise please open the link below

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

Upvotes: 1

Related Questions