I am developing a Mozilla Thunderbird plug-in and need to get the user's email address.
Question: How do I retrieve this address?
I will use it inside a JavaScript.
You should first keep in mind that a user can have multiple e-mail addresses (from multiple accounts or even multiple identities for one account), and you have to decide in which one you are interested.
Note: there may exist an easier way then described below, e.g. a helper function in the existing Thunderbird Code. You could try to search comm-central for it
You somehow have to get the nsIMsgIdentity
for the identity you are interested in. It has an email
property, with the e-mail adress as a string.
One way to get all Identities should be via the allIdentities
of nsIMsgAccountManager
(didn't test it).
Use the follwing code to get the nsIMsgAccountManager
:
Components.utils.import("resource:///modules/mailServices.js");
let accountManager = MailServices.accounts
If you have an nsIArray
of nsIMsgIdentity
, you can use the following code to loop over them:
for (let identity in fixIterator(identities, Components.interfaces.nsIMsgIdentity)) {
}
Overview of some interesting interfaces: https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_interfaces
Some account example Code: https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Account_examples