How to use Delphi to get email message text from Thunderbird
-
13-09-2019 - |
Question
What I do now with Outlook:
I receive email orders for products. I select a single or multiple emails in Outlook (a single order can have multiple emails associated with it) and then switch to my Delphi coded OrderManager program and click "Import". It uses Outlook's COM automation interface to read the text of each message, parses and processes each one.
The question is, can I do this using Thunderbird instead? Does Thunderbird have a COM interface? I must be googling the wrong keywords because I haven't found anything yet.
Btw, I do have a version of my OrderManager that just reads the emails directly from my email server using Indy, but for several reasons I'd like to try to read them from Firefox.
Any suggestions, links to docs, or code samples will be greatly appreciated!
Solution
Check this link out.
You could write a C or C++ wrapper around XPCOM and then use that wrapper within Delphi.
There is also an open source XPCOM wrapper written in Delphi. You might want to check that out as well. Thanks Stijn for pointing that out.
Hope it helps.
OTHER TIPS
You could also parse Thunderbird's mailbox files yourself.
- From
%APPDATA%\Thunderbird\profiles.ini
, read where the profile folder is located (if there's more than one profile, look through sectionsProfile
0..Profile
n for the one that has the valueDefault=1
) - Each subfolder of the
Mail
and/orImapMail
subfolders of the profile folder represents an account (Mail
contains POP accounts,ImapMail
contains IMAP accounts); - Look through all files whose names don't end with .dat or .msf, and whose contents start with 'From ' (F, r, o, m, and a space). Those are the mailbox files.
- Every line that starts with '
From
' indicates a new message. Use theX-Mozilla-Status
header to figure out whether the message is still valid, or whether it's been marked for deletion. (You can use theCDO.Message
COM object to parse the message for you, if you want).
You should recurse for each subfolder ending on '.sbd', since that will contain that mailbox's subfolders (E.g. Inbox.sbd
will contain the mail folders under the Inbox).
Be wary of file locking issues, however.