Stef Merlijn
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('\Softwar e\Microsof t\Internet Account Manager\Accounts',False);
Registry.GetKeyNames(MijnL ijst);
Registry.CloseKey;
For i := 0 to MijnLijst.Count-1 do
begin
Registry.OpenKey('\Softwar e\Microsof t\Internet Account Manager\Accounts\'+MijnLij st[i],Fals e);
If Registry.ValueExists('SMTP Email Address') then
begin
MijnCombo.Items.Add(Regist ry.ReadStr ing('SMTP Email Address'));
end;
Registry.CloseKey;
end;
MijnLijst.Free;
Registry.Free;
end;
Please supply some working code.
Thanks a lot for your help.
Stef
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
var
Registry : TRegistry;
MijnLijst : Tstrings;
i : Integer;
begin
MijnLijst := TStringList.Create;
Registry := Tregistry.Create;
Registry.RootKey := HKEY_CURRENT_USER;
Registry.OpenKey('\Softwar
Registry.GetKeyNames(MijnL
Registry.CloseKey;
For i := 0 to MijnLijst.Count-1 do
begin
Registry.OpenKey('\Softwar
If Registry.ValueExists('SMTP
begin
MijnCombo.Items.Add(Regist
end;
Registry.CloseKey;
end;
MijnLijst.Free;
Registry.Free;
end;
Please supply some working code.
Thanks a lot for your help.
Stef
ASKER
Robert, thank you for that.
But how can I retrieve the email-account from there from within Delphi (like above for Outlook Express)?
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.ac count1.ide ntities", "id1");
user_pref("mail.account.ac count1.ser ver", "server1");
user_pref("mail.account.ac count2.ser ver", "server2");
user_pref("mail.account.ac count3.ide ntities", "id2");
user_pref("mail.account.ac count3.ser ver", "server3");
user_pref("mail.account.ac count4.ide ntities", "id3");
user_pref("mail.account.ac count4.ser ver", "server4");
user_pref("mail.accountman ager.accou nts", "account2,account3,account 1,account4 ");
user_pref("mail.accountman ager.defau ltaccount" , "account2");
user_pref("mail.accountman ager.local foldersser ver", "server2");
user_pref("mail.compose.at tach.dir", "<a path>");
user_pref("mail.default_ht ml_action" , 1);
user_pref("mail.display_gl yph", false);
user_pref("mail.forward_me ssage_mode ", 2);
user_pref("mail.identity.i d1.compose _html", false);
user_pref("mail.identity.i d1.doBcc", false);
user_pref("mail.identity.i d1.draft_f older", "mailbox://nobody@Local%20 Folders/Dr afts");
user_pref("mail.identity.i d1.drafts_ folder_pic ker_mode", "0");
user_pref("mail.identity.i d1.escaped VCard", "");
user_pref("mail.identity.i d1.fcc_fol der", "mailbox://nobody@Local%20 Folders/Se nt");
user_pref("mail.identity.i d1.fcc_fol der_picker _mode", "0");
user_pref("mail.identity.i d1.fullNam e", "xxxxxx");
user_pref("mail.identity.i d1.organiz ation", "");
user_pref("mail.identity.i d1.reply_t o", "");
user_pref("mail.identity.i d1.smtpSer ver", "smtp1");
user_pref("mail.identity.i d1.station ery_folder ", "mailbox://nobody@Local%20 Folders/Te mplates");
user_pref("mail.identity.i d1.tmpl_fo lder_picke r_mode", "0");
user_pref("mail.identity.i d1.userema il", "xxxxx@yyyy.zz");
user_pref("mail.identity.i d1.valid", true);
user_pref("mail.identity.i d2.compose _html", false);
user_pref("mail.identity.i d2.doBcc", false);
user_pref("mail.identity.i d2.draft_f older", "mailbox://nobody@Local%20 Folders/Dr afts");
user_pref("mail.identity.i d2.drafts_ folder_pic ker_mode", "0");
user_pref("mail.identity.i d2.escaped VCard", "");
user_pref("mail.identity.i d2.fcc_fol der", "mailbox://nobody@Local%20 Folders/Se nt");
user_pref("mail.identity.i d2.fcc_fol der_picker _mode", "0");
user_pref("mail.identity.i d2.fullNam e", "xxxxxxx");
user_pref("mail.identity.i d2.organiz ation", "");
user_pref("mail.identity.i d2.reply_t o", "");
Here an excerpt from my file (with deleted names)
user_pref("mail.account.ac
user_pref("mail.account.ac
user_pref("mail.account.ac
user_pref("mail.account.ac
user_pref("mail.account.ac
user_pref("mail.account.ac
user_pref("mail.account.ac
user_pref("mail.accountman
user_pref("mail.accountman
user_pref("mail.accountman
user_pref("mail.compose.at
user_pref("mail.default_ht
user_pref("mail.display_gl
user_pref("mail.forward_me
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
user_pref("mail.identity.i
ASKER
I realy need a complete solution to my problem.
Based on what you wrote I've no idea where to start.
Based on what you wrote I've no idea where to start.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\Window s\CurrentV ersion\Exp lorer\Shel l 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(ProfileFil ename);
LoadPrefsJS;
// Memo1.Lines.Add('********* ********** *********' );
// Memo1.Lines.Add('POP3 Data');
// Memo1.Lines.Add('********* ********** *********' );
// Memo1.Lines.Add('There are ' + IntToStr(NumberOfPOP3Accou nts) + ' POP3 accounts');
DisplayPOP3AccountData;
// Memo1.Lines.Add('********* ********** *********' );
// Memo1.Lines.Add('ALL THE STORED VALUES');
// Memo1.Lines.Add('********* ********** *********' );
// Memo1.lines.addstrings(pre fsJS);
end;
procedure TForm1.LoadPrefsJS;
var i, j: integer;
S, SName, Svalue: string;
tempSL: TStringList;
begin
tempSL := TStringList.Create;
try
tempSL.LoadFromFile(Profil eFilename) ;
// 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.NumberOfPOP3Account s: integer;
var i: integer;
begin
result := 0;
i := 1;
while PrefsJS.Values['mail.serve r.server' + IntToStr(i) + '.type'] <> '' do
begin
if lowercase(PrefsJS.Values[' mail.serve r.server' + IntToStr(i) + '.type']) = 'pop3' then
result := result + 1;
inc(i);
end;
end;
procedure TForm1.DisplayPOP3AccountD ata;
var i: integer;
begin
i := 1;
while PrefsJS.Values['mail.ident ity.id' + IntToStr(i) + '.useremail'] <> '' do
begin
memo1.Lines.Add(PrefsJS.Va lues['mail .identity. id' + IntToStr(i) + '.useremail']);
inc(i);
end;
end;
end.
Thanks, Stef
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:
begin
PrefsJS.Clear;
PrefsJS.Free;
end;
procedure TForm1.Button1Click(Sender
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\Window
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
try
ProfileFilename :=
sAppData + '\Thunderbird\' +
StringReplace(ReadString('
'\prefs.js';
finally
free;
end;
// Memo1.lines.add(ProfileFil
LoadPrefsJS;
// Memo1.Lines.Add('*********
// Memo1.Lines.Add('POP3 Data');
// Memo1.Lines.Add('*********
// Memo1.Lines.Add('There are ' + IntToStr(NumberOfPOP3Accou
DisplayPOP3AccountData;
// Memo1.Lines.Add('*********
// Memo1.Lines.Add('ALL THE STORED VALUES');
// Memo1.Lines.Add('*********
// Memo1.lines.addstrings(pre
end;
procedure TForm1.LoadPrefsJS;
var i, j: integer;
S, SName, Svalue: string;
tempSL: TStringList;
begin
tempSL := TStringList.Create;
try
tempSL.LoadFromFile(Profil
// 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.NumberOfPOP3Account
var i: integer;
begin
result := 0;
i := 1;
while PrefsJS.Values['mail.serve
begin
if lowercase(PrefsJS.Values['
result := result + 1;
inc(i);
end;
end;
procedure TForm1.DisplayPOP3AccountD
var i: integer;
begin
i := 1;
while PrefsJS.Values['mail.ident
begin
memo1.Lines.Add(PrefsJS.Va
inc(i);
end;
end;
end.
Thanks, Stef
\Documents and Settings\<User>\Applicatio
Do not forget that the name "\Documents and Settings\<User>\Applicatio