Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In GNU/Linux, how can one start Thunderbird in the background, let it run for a few minutes for emails to be fetched, and close it afterwards?

share|improve this question
    
Does Thunderbird's "-kill" command-line argument wait until after new messages have been downloaded? It's undocumented, but perhaps it's worth a try? developer.mozilla.org/en/… – Randolf Richardson Jun 18 '11 at 5:45
up vote 3 down vote accepted

It appears that thunderbird does not support this functionality, however, there are some discussions here and here that discuss options for doing this with your window manager/desktop environment. Essentially by running it minimized, with no system tray icon, etc.

To make it only run for a few minutes, you could start TB from a script:

#!/bin/bash
/usr/bin/thunderbird &
sleep 300 # 5 minutes
kill $!

Another option would be to use another program to download your mail for you, and have Thunderbird read the mail from your localdisk. OfflineIMAP does a good job if your mail server supports IMAP. Fetchmail is another option that works with POP3, as well.

share|improve this answer
    
I am currently using fetchmail, procmail, and cron. But I was wondering if this could be done, mostly, in one place: Thunderbird. Context switches considered harmful! – Omid Jun 18 '11 at 5:42

The solution I've settled for (thanks to Flimzy's answer) is to use the following script, saved in, say, $HOME/thunderbird_cron.sh

#!/bin/bash
/usr/bin/alltray /usr/bin/thunderbird &
sleep 5m
killall thunderbird-bin

together with the following crontab -e entry

0 0 * * * env DISPLAY=:0.0 $HOME/thunderbird_cron.sh

to run Thunderbird for 5 minutes once a day at midnight, to fetch emails, and have it closed afterwards.

  • kill $!, contrary to what's suggested by Danniel Beck, does not work when the script is run by cron as $! does not return the correct process id there.

  • The env DISPLAY=:0.0 portion will tell cron to use the first screen of the current monitor for Thunderbird. It has to be there for a GUI application to be run by cron.

  • alltray is used to run Thunderbird docked to the tray, effectively making the process of opening and closing invisible to the user.

Update: Even if the option "Check for new messages at startup" is selected (under Account Settings/Server Settings) Thunderbird does not start downloading new messages until after a folder of your email account is selected. (The version I've tested is 3.1.10 under Ubuntu 10.04 LTS.) To automate this selection at startup, the add-on Folderpane Tools can be used. (The method discussed at http://kb.mozillazine.org/Show_Inbox_when_starting_Thunderbird does not work.)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .