Session logging for mail/news
This article is about troubleshooting techniques for advanced users who are investigating problems with servers. It applies to all of the server types that Thunderbird connects to:
POP3 For getting mail IMAP For getting mail SMTP For sending mail NNTP For usenet news HTTP For RSS feeds LDAP For address books
These methods are only useful for investigating problems that occur after Thunderbird establishes a connection to a server. If Thunderbird cannot connect to the server, then it is pointless trying to log the connection—in these cases, see: Network tools for server connections
To use these methods for investigating secure authentication, you will need additional tools depending on the authentication method.
Methods for logging
There are three methods for logging server connections:
- Thunderbird itself
- A logging proxy
- A packet sniffer
Using Thunderbird
Thunderbird can create a log file for the server types POP3, IMAP, SMTP, NNTP and HTTP, and MIME and LDAP protocols.
When you use Thunderbird to log a connection:
- You do not see all the authentication information, so you might not be able to investigate authentication problems in detail.
- You can log secure (SSL and TLS) connections.
To create the log file, follow the instructions on the Mozilla web page linked below. Use log level 5, and remember to specify POP3:5, IMAP:5, SMTP:5, NNTP:5, nsHttp:5, MIME:5 or LDAP:5, depending on which type of server or protocol you are investigating. (The module nsHttp is not mentioned on the linked page.)
Exiting Thunderbird usually does not close any existing connections to a mail server, it can take 5-10 minutes for them to time out. It's much easier to debug a problem when you can also log it making a new connection. For example, if you enabled IMAP logging and the connection to the AIM mail server was still open you would see something roughly like:
- 0[34988]: 2310cc0:imap.cs.com:NA:SetupWithUrl: clearing IMAP_CONNECTION_IS_OPEN
If the log file is empty that normally means you either didn't configure the logging correctly (you need to specify POP3:5 , not POP:5 for example) or you couldn't make a TCP-IP connection to the mail server for some reason. You could use netstat to list your connections. Run it from a console window/DOS box.
Its recommended that you add a timestamp. A combination like
- MOZ_LOG=imap:5,timestamp
would add the time of an event to each entry.
Sample batch files for Windows
The environmental variables NSPR_LOG_MODULES and NSPR_LOG_FILE are being replaced with MOZ_LOG and MOZ_LOG_FILE starting with Thunderbird 55.0a1. These sample batch files use both so that they should work with any version.
To enable logging for a IMAP account create a imap.bat file at %APPDATA%\Thunderbird\Profiles (enter that string in the Windows search box and press Enter to go there using Windows Explorer) using a text editor such as Notepad. This is the default location that profiles are created in (as child directories). The log file will be created in the same directory as the imap.bat file.
Double click on the batch file and it will start Thunderbird with IMAP logging enabled. Duplicate the problem and exit Thunderbird. Afterwards open the imap.log log file with a text editor to view the log. The log file is usually too long to post in the forums. If you are asking for help in the forums it is suggested that you log into https://pastebin.com , https://www.dropbox.com or https://docs.google.com/document/ , upload the log file and then post a link to it in the forum. The log file does not contain passwords. It will contain some strings that use portions of your email address but it is garbled, so that spammers using a spider to collect email addresses should ignore it.
For a IMAP account create the following imap.bat file:
set MOZ_LOG=IMAP:5,timestamp set MOZ_LOG_FILE=%APPDATA%\Thunderbird\Profiles\imap.log set NSPR_LOG_MODULES=IMAP:5,timestamp set NSPR_LOG_FILE=%APPDATA%\Thunderbird\Profiles\imap.log "%ProgramFiles(x86)%\Mozilla Thunderbird\thunderbird.exe"
For a POP account create the following pop.bat file instead:
set MOZ_LOG=POP3:5,timestamp set MOZ_LOG_FILE=%APPDATA%\Thunderbird\Profiles\pop.log set NSPR_LOG_MODULES=POP3:5,timestamp set NSPR_LOG_FILE=%APPDATA%\Thunderbird\Profiles\pop.log "%ProgramFiles(x86)%\Mozilla Thunderbird\thunderbird.exe"
To log sending a email message (SMTP) create the following smtp.bat file instead:
set MOZ_LOG=SMTP:5,timestamp set MOZ_LOG_FILE=%APPDATA%\Thunderbird\Profiles\smtp.log set NSPR_LOG_MODULES=SMTP:5,timestamp set NSPR_LOG_FILE=%APPDATA%\Thunderbird\Profiles\smtp.log "%ProgramFiles(x86)%\Mozilla Thunderbird\thunderbird.exe"
You can replace %APPDATA%\Thunderbird\Profiles with %USERPROFILE%\Desktop if you want to display the log file on your desktop instead. Or replace it with any path you want.
The logging is not account specific, it will log everything for that type of account. It is usually a good idea to temporarily disable checking for new mail in the other accounts by unchecking "check for new mail on startup" etc. before using the batch file, and not selecting any of the other accounts folders in the folder pane while duplicating the problem. Otherwise not only will it log everything for every account of that type, but it may intermingle the logging (making it much harder to read).
Other types of problems you can solve
You can also log memory usage using MSGDB:5 to help diagnose memory usage problems. If you build a debug version of Thunderbird there are other logging options such as MAPI, msgcompose, imapoffline etc. that may be useful for debugging.
Using a proxy
A logging proxy is an additional program that logs a specific connection.
When you use a proxy:
- You can log any server type.
- You do not see Thunderbird's connection states. This simplifies the log, but it might make some problems more difficult to discover.
- You see the raw data with no explanatory information.
- You see all the authentication information. However, investigating secure authentication requires additional tools.
- You cannot successfully log a secure (SSL) connection, nor a TLS connection after the initial negotiation.
To configure a proxy, either change Thunderbird's server settings, or use Thunderbird's proxy settings to specify localhost (your own computer, where the proxy is running) as the proxy server. By changing settings in Thunderbird, you risk changing the nature of the problem that you are investigating. If possible, check the proxy configuration with a working server before you use it with the server you are investigating.
To change Thunderbird's server settings, point Thunderbird at the server localhost and point the logging proxy at the real server.
To change Thunderbird's proxy settings, choose: Tools – Options... – General – Connection Settings..., choose "Manual proxy configuration", set the HTTP proxy to localhost, and check the box "Use this proxy server for all protocols". Use whatever port you have configured in the proxy—for example, 80. Point the logging proxy at the real server and port.
Some examples of logging proxies that you can download are:
- Trivial Proxy (Windows only)
- TCPreen (cross-platform)
Using a packet sniffer
A packet sniffer is an additional program that logs network traffic. You usually configure the packet sniffer to filter the log, so that you only see the parts that interest you. The resulting log contains information similar to a proxy log, but it might be presented in a much more complex way, depending on the sniffer and on how you configure it.
When you use a packet sniffer:
- You can log any server type.
- You do not change any settings in Thunderbird.
- You see the raw data with no explanatory information.
- You do not see Thunderbird's connection states. This simplifies the log, but it might make some problems more difficult to discover.
- You see all the authentication information. However, investigating secure authentication requires additional tools.
- You cannot successfully log a secure (SSL) connection, nor a TLS connection after the initial negotiation.
Configuring a packet sniffer depends on the sniffer.
Some examples of packet sniffers that you can download are:
Interpreting a connection log
To interpret a connection log, you need to understand something about how the server works and how Thunderbird works.
The server specifications are Internet standards published as RFCs. There are some links to them in the External links section below.
For POP3, SMTP and NNTP, Thunderbird works by computing a connection state that tells it what to expect from the server and what to do next. These connection states are internal to Thunderbird. They might be different in different releases of Thunderbird. To understand the connection states in detail, you might have to read Thunderbird's C++ source code.
POP3 connection states
|
|
|
SMTP connection states
|
|
|
NNTP connection states
|
|
|
Examples
Here is a proxy log of a connection to a POP3 server. There are no messages on the server:
+OK Hello there. AUTH -ERR Invalid command. CAPA +OK Here's what I can do: SASL LOGIN CRAM-MD5 CRAM-SHA1 TOP USER LOGIN-DELAY 10 PIPELINING UIDL IMPLEMENTATION Courier Mail Server . AUTH LOGIN + VXNlcm5hbWU6 anVzdC50ZXN0aW5nQGV4YW1wbGUubmV0DQo= + UGFzc3dvcmQ6 Zm9vYmFyMTIzDQo= +OK logged in. STAT +OK 0 0 QUIT +OK Bye-bye.
The base64 strings that you see are:
VXNlcm5hbWU6 Username: anVzdC50ZXN0aW5nQGV4YW1wbGUubmV0DQo= just.testing@example.net (the username) UGFzc3dvcmQ6 Password: Zm9vYmFyMTIzDQo= foobar123 (the password)
Here is a Thunderbird log of the same connection:
0[ef1790]: Entering NET_ProcessPop3 18 0[ef1790]: POP3: Entering state: 1 0[ef1790]: POP3: Entering state: 2 0[ef1790]: POP3: Entering state: 4 0[ef1790]: RECV: +OK Hello there. 0[ef1790]: POP3: Entering state: 29 0[ef1790]: SEND: AUTH 0[ef1790]: Entering NET_ProcessPop3 23 0[ef1790]: POP3: Entering state: 3 0[ef1790]: RECV: -ERR Invalid command. 0[ef1790]: POP3: Entering state: 30 0[ef1790]: POP3: Entering state: 31 0[ef1790]: SEND: CAPA 0[ef1790]: Entering NET_ProcessPop3 142 0[ef1790]: POP3: Entering state: 3 0[ef1790]: RECV: +OK Here's what I can do: 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: SASL LOGIN CRAM-MD5 CRAM-SHA1 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: TOP 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: USER 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: LOGIN-DELAY 10 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: PIPELINING 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: UIDL 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: IMPLEMENTATION Courier Mail Server 0[ef1790]: POP3: Entering state: 32 0[ef1790]: RECV: . 0[ef1790]: POP3: Entering state: 33 0[ef1790]: POP3: Entering state: 35 0[ef1790]: SEND: AUTH LOGIN 0[ef1790]: Entering NET_ProcessPop3 16 0[ef1790]: POP3: Entering state: 3 0[ef1790]: RECV: + VXNlcm5hbWU6 0[ef1790]: POP3: Entering state: 36 0[ef1790]: POP3: Entering state: 5 0[ef1790]: SEND: anVzdC50ZXN0aW5nQGV4YW1wbGUubmV0DQo= 0[ef1790]: Entering NET_ProcessPop3 16 0[ef1790]: POP3: Entering state: 3 0[ef1790]: RECV: + UGFzc3dvcmQ6 0[ef1790]: POP3: Entering state: 34 0[ef1790]: POP3: Entering state: 6 0[ef1790]: Logging suppressed for this command (it probably contained authentication information) 0[ef1790]: Entering NET_ProcessPop3 16 0[ef1790]: POP3: Entering state: 3 0[ef1790]: RECV: +OK logged in. 0[ef1790]: POP3: Entering state: 34 0[ef1790]: POP3: Entering state: 7 0[ef1790]: SEND: STAT 0[ef1790]: Entering NET_ProcessPop3 9 0[ef1790]: POP3: Entering state: 3 0[ef1790]: RECV: +OK 0 0 0[ef1790]: POP3: Entering state: 8 0[ef1790]: POP3: Entering state: 22 0[ef1790]: SEND: QUIT 0[ef1790]: Entering NET_ProcessPop3 14 0[ef1790]: POP3: Entering state: 3 0[ef1790]: RECV: +OK Bye-bye. 0[ef1790]: POP3: Entering state: 43 0[ef1790]: POP3: Entering state: 23 0[ef1790]: POP3: Entering state: 25
Rich logging using Gloda
The global database (gloda) has been enhanced to support additional logging and context information. Logsploder is a XULRunner application that supports using these features. See logsploder, circa a year+ ago for more information. This functionality isn't useful for most users, its intended mainly to support unit testing.
See also
External links
Wikipedia articles (including links to RFCs):
- Post Office Protocol (POP3)
- Internet Message Access Protocol (IMAP)
- Simple Mail Transfer Protocol (SMTP)
- Network News Transfer Protocol (NNTP)
- Hypertext Transfer Protocol (HTTP)
- Lightweight Directory Access Protocol (LDAP)
Protocol guides (they focus on the actual commands and which RFC applies to a specific protocol command):
- Post Office Protocol (POP3)
- Internet Message Access Protocol (IMAP)
- Simple Mail Transfer Protocol (SMTP)
- Network News Transfer Protocol (NNTP)
- Hypertext Transfer Protocol (HTTP)
- Lightweight Directory Access Protocol (LDAP)
Sometimes its useful to compare session logs for another email client and Thunderbird.
- How to enable and interpret the Outlook Express Pop3.log File
- How to enable and interpret the Outlook Express Smtp.log File
Additional information on how the logging works:
- Thunderbird:Backend Hacking Guide For Newbies describes several frameworks used by Thunderbird, such as NSPR. NSPR performs the logging.
- IMAP - MozillaWiki helps you understand the calls to various methods that are logged in the IMAP log file. It has more than just a IMAP protocol trace.
- NSPR logging
- Web Site Quality Assurance Testing using Mozilla describes NSPR JavaScript, Cookie and HTTP logging in release builds.
- MozillaZine thread about complete list of protocols/modules for NSPR_LOG_MODULES