[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Retrieve E-mail accounts from Thunderbird (email client)

Posted on 2005-04-17
6
Medium Priority
?
615 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:Stef Merlijn
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 13801062
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.
0
 

Author Comment

by:Stef Merlijn
ID: 13801259
Robert, thank you for that.
But how can I retrieve the email-account from there from within Delphi (like above for Outlook Express)?
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 13801859
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", "");
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Stef Merlijn
ID: 13802001
I realy need a complete solution to my problem.
Based on what you wrote I've no idea where to start.
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 13812383
Here's a real quick example I wrote for you. Never looked at Thunderbird settings before but thought I'd jump right into it

put a button and a memo on a form

!! Don't forget to hook up the FormCreate, FormDestroy, and ButtonClick events! !
THis should work if you have hunderbird installed on teh same machine with the current logged on user
if you are not runnin g it this way then set
ProfileFilename manually

hth, Loki

unit Unit1;

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;
    end;

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

procedure TForm1.Button1Click(Sender: TObject);
//const
//    RootApplicationDir
    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.server.server' + IntToStr(i) + '.type'] <> '' do
        begin
            if lowercase(PrefsJS.Values['mail.server.server' + IntToStr(i) + '.type']) = 'pop3' then
            begin
//it's a pop3 account, so lets get the information
// display the username
                memo1.Lines.Add('Account ' + IntToStr(i) + ' Username = ' +
                  PrefsJS.Values['mail.server.server' + IntToStr(i) + '.username']);
// display the pop3 hostname
                memo1.Lines.Add('Account ' + IntToStr(i) + ' pop3 hostname = ' +
                  PrefsJS.Values['mail.server.server' + IntToStr(i) + '.hostname']);
            end;
            inc(i);
        end;

// display smtp servers
        i := 1;
        while PrefsJS.Values['mail.smtpserver.smtp' + IntToStr(i) + '.hostname'] <> '' do
        begin
             memo1.Lines.Add('SMTP Server (not account specific) ' + IntToStr(i) + ' hostname = ' +
               PrefsJS.Values['mail.smtpserver.smtp' + IntToStr(i) + '.hostname']);
            inc(i);
        end;
    end;

end.
0
 

Author Comment

by:Stef Merlijn
ID: 13813125
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question