Link to home
Start Free TrialLog in
Avatar of Stef Merlijn
Stef MerlijnFlag for Netherlands

asked on

Retrieve E-mail accounts from Thunderbird (email client)

Hi,

How can I retrieve the e-mail accounts (pop3) from thunderbird?
Currently I use the code below to retrieve these from Outlook Express.
Scanning through the registry it seems Thunderbird doesn't use the registry to store the accounts???


procedure TForm1.HaalEmailAccountsOp(MijnCombo : TComboBox);
var
  Registry   : TRegistry;
  MijnLijst  : Tstrings;
  i          : Integer;
begin
  MijnLijst        := TStringList.Create;
  Registry         := Tregistry.Create;
  Registry.RootKey := HKEY_CURRENT_USER;
  Registry.OpenKey('\Software\Microsoft\Internet Account Manager\Accounts',False);
  Registry.GetKeyNames(MijnLijst);
  Registry.CloseKey;
  For i := 0 to MijnLijst.Count-1 do
  begin
    Registry.OpenKey('\Software\Microsoft\Internet Account Manager\Accounts\'+MijnLijst[i],False);
    If Registry.ValueExists('SMTP Email Address') then
    begin
      MijnCombo.Items.Add(Registry.ReadString('SMTP Email Address'));
    end;
    Registry.CloseKey;
  end;
  MijnLijst.Free;
  Registry.Free;
end;


Please supply some working code.
Thanks a lot for your help.
Stef
Avatar of robert_marquardt
robert_marquardt

All Mozilla family browsers use a prefs.js file.which is stored in the preferences directory of the user.
\Documents and Settings\<User>\Application Data\Mozilla\Profiles\default\<some generated name.slt\prefs.js

Do not forget that the name "\Documents and Settings\<User>\Application Data" is localized.
Avatar of Stef Merlijn

ASKER

Robert, thank you for that.
But how can I retrieve the email-account from there from within Delphi (like above for Outlook Express)?
This is a text file (in fact a progam source to be interpreted). Have a look at it. It should be easy to understand.

Here an excerpt from my file (with deleted names)

user_pref("mail.account.account1.identities", "id1");
user_pref("mail.account.account1.server", "server1");
user_pref("mail.account.account2.server", "server2");
user_pref("mail.account.account3.identities", "id2");
user_pref("mail.account.account3.server", "server3");
user_pref("mail.account.account4.identities", "id3");
user_pref("mail.account.account4.server", "server4");
user_pref("mail.accountmanager.accounts", "account2,account3,account1,account4");
user_pref("mail.accountmanager.defaultaccount", "account2");
user_pref("mail.accountmanager.localfoldersserver", "server2");
user_pref("mail.compose.attach.dir", "<a path>");
user_pref("mail.default_html_action", 1);
user_pref("mail.display_glyph", false);
user_pref("mail.forward_message_mode", 2);
user_pref("mail.identity.id1.compose_html", false);
user_pref("mail.identity.id1.doBcc", false);
user_pref("mail.identity.id1.draft_folder", "mailbox://nobody@Local%20Folders/Drafts");
user_pref("mail.identity.id1.drafts_folder_picker_mode", "0");
user_pref("mail.identity.id1.escapedVCard", "");
user_pref("mail.identity.id1.fcc_folder", "mailbox://nobody@Local%20Folders/Sent");
user_pref("mail.identity.id1.fcc_folder_picker_mode", "0");
user_pref("mail.identity.id1.fullName", "xxxxxx");
user_pref("mail.identity.id1.organization", "");
user_pref("mail.identity.id1.reply_to", "");
user_pref("mail.identity.id1.smtpServer", "smtp1");
user_pref("mail.identity.id1.stationery_folder", "mailbox://nobody@Local%20Folders/Templates");
user_pref("mail.identity.id1.tmpl_folder_picker_mode", "0");
user_pref("mail.identity.id1.useremail", "xxxxx@yyyy.zz");
user_pref("mail.identity.id1.valid", true);
user_pref("mail.identity.id2.compose_html", false);
user_pref("mail.identity.id2.doBcc", false);
user_pref("mail.identity.id2.draft_folder", "mailbox://nobody@Local%20Folders/Drafts");
user_pref("mail.identity.id2.drafts_folder_picker_mode", "0");
user_pref("mail.identity.id2.escapedVCard", "");
user_pref("mail.identity.id2.fcc_folder", "mailbox://nobody@Local%20Folders/Sent");
user_pref("mail.identity.id2.fcc_folder_picker_mode", "0");
user_pref("mail.identity.id2.fullName", "xxxxxxx");
user_pref("mail.identity.id2.organization", "");
user_pref("mail.identity.id2.reply_to", "");
I realy need a complete solution to my problem.
Based on what you wrote I've no idea where to start.
ASKER CERTIFIED SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks you very much.  TheRealLoki
This is what I needed. I've stripped the code so only the useremails will be added into the memo.

unit ThunderbirdUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry, IniFiles;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
        PrefsJS: TStringList;
        ProfileFilename: string;
  public
    { Public declarations }
    procedure LoadPrefsJS;
    function NumberOfPOP3Accounts: integer;
    procedure DisplayPOP3AccountData;
  end;

var
  Form1: TForm1;

IMPLEMENTATION

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  PrefsJS := TStringList.Create;
  memo1.Clear;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  PrefsJS.Clear;
  PrefsJS.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var reg : TRegistry;
    i : cardinal;
    sAppData: string;
    sUser: string;
begin
  // first we try to get teh Application Data folder
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_CURRENT_USER;
    reg.LazyWrite := false;
    reg.OpenKey(
    'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
    false);
    sAppData := reg.ReadString('AppData');
    // memo1.lines.add(sAppData);
    reg.CloseKey
  finally
    reg.free;
  end;

  // next we read the default profile path from profile.ini
  with TIniFile.Create(sAppData + '\Thunderbird\Profiles.ini') do
  try
    ProfileFilename :=
    sAppData + '\Thunderbird\' +
    StringReplace(ReadString('Profile0', 'Path', ''), '/', '\', [rfReplaceAll]) +
    '\prefs.js';
  finally
    free;
  end;

  // Memo1.lines.add(ProfileFilename);
  LoadPrefsJS;
  // Memo1.Lines.Add('****************************');
  // Memo1.Lines.Add('POP3 Data');
  // Memo1.Lines.Add('****************************');
  // Memo1.Lines.Add('There are ' + IntToStr(NumberOfPOP3Accounts) + ' POP3 accounts');
  DisplayPOP3AccountData;
  // Memo1.Lines.Add('****************************');
  // Memo1.Lines.Add('ALL THE STORED VALUES');
  // Memo1.Lines.Add('****************************');
  // Memo1.lines.addstrings(prefsJS);
end;

procedure TForm1.LoadPrefsJS;
var i, j: integer;
    S, SName, Svalue: string;
    tempSL: TStringList;
begin
  tempSL := TStringList.Create;
  try
    tempSL.LoadFromFile(ProfileFilename);
    // while loop to reformat. Strip off the 'user_pref("' and use "values/names" of TStringList
    for i := 0 to pred(tempSL.Count) do
    begin
      s := tempSL[i];
      if pos('user_pref("', lowercase(s)) = 1 then
      begin
        delete(s, 1, length('user_pref("'));
        j := pos('", ', S);
        SName := copy(s, 1, j-1);
        delete(S, 1, (j-1) + length('", '));
        if s[1] = '"'then delete(S, 1, 1);
        j := pos('"', S);
        SValue := copy(S, 1, j-1);
        PrefsJS.Values[SName] := SValue; // load the value into stringlist
      end;
    end;
  finally
    tempSL.Clear;
    tempSL.Free;
  end;
end;

function TForm1.NumberOfPOP3Accounts: integer;
var i: integer;
begin
  result := 0;
  i := 1;
  while PrefsJS.Values['mail.server.server' + IntToStr(i) + '.type'] <> '' do
  begin
    if lowercase(PrefsJS.Values['mail.server.server' + IntToStr(i) + '.type']) = 'pop3' then
      result := result + 1;
    inc(i);
  end;
end;

procedure TForm1.DisplayPOP3AccountData;
var i: integer;
begin
  i := 1;
  while PrefsJS.Values['mail.identity.id' + IntToStr(i) + '.useremail'] <> '' do
  begin
    memo1.Lines.Add(PrefsJS.Values['mail.identity.id' + IntToStr(i) + '.useremail']);
    inc(i);
  end;
end;

end.

Thanks, Stef