User avatar
DetlevSchm
Posts: 72
Joined: Tue Mar 12, 2013 8:43 am
Location: 3rd planet

claws-mail automation

Thu Mar 28, 2013 11:31 am

I am trying to call claws-mail from within a script at certain irregular intervals to let it check for new mail.
(I do not want to have claws-mail open on the desktop all the time to do its own check in the foreground.)

If I submit "claws-mail --statistics" for example, I get that information on stdout, everything as expected.

However, when I submit "claws-mail --receive-all", claws-mail opens a window (bad), does its job (good), and remains open (bad).

I tried "claws-mail --receive-all --quit", but then it just quits.
(What is the --quit option good for? If it just quits, I do not need to call it in the first place.)

Also, I cannot use cron, because claws-mail requires the GUI.

Is there any elegant way to let claws-mail quit in this context, without killing its process?

_____________________________
I did not found this subject covered on the Claws support site,
nor in general on the Internet, nor in particular in these forums.

DLTaylor
Posts: 1
Joined: Tue Oct 09, 2018 12:37 am

Re: claws-mail automation

Tue Oct 09, 2018 2:09 am

A long time since first post, but I want to do similar; to update Claws-Mail inbox as a regular cron job.
This will then be displayed on a single-line LCD module showing the result of 'claws-mail --status inbox'.
i.e. So I can see at a glance if anything new has arrived.

Using a RPi-3 with Raspian-Stretch-Lite (although I would expect this to work in any RPi hardware):
I am doing this over a network from a netbook computer using 'ssh' to login and to forward its X display server, to the RPi running as a 'headless server' (this ought to work on the primary GUI as well, but you may need to install the full Raspbian distro, and not the 'lite' version I've chosen) .

The Claws-Mail documentation is a bit lacking in explaing this next part; it has to in effect run as a background daemon for commands such as:
claws-mail --status-all
or
claws-mail --statistics
to function. (Else it replies "claws-mail is not running"). To get it started, type from a command line:
claws-mail --receive-all &
..the '--receive-all' option not only downloads emails but also puts it into a foreground GUI.
..the trailing '&' is the standard unix/linux way of sending the command into the background and returning control back to the command line. Doing this has the effect of detaching the GUI from the command line, and both are selectable with the mouse.

Now the important part: Claws-Mail needs to set up its GUI, sending commands to an 'X server', but that need not be a 'real' X server!

From other forums, it is explained that 'cron' is a command line only environment, and thus knows nothing about how to hand over the ports of an X server to run a GUI application. So they suggest to manually do this by putting this into your crontab file (use command 'crontab -e'):
# every ten minutes, set environment var to default X server, command
*/10 * * * * DISPLAY=:0 claws-mail --receive-all
But this did not work for me. I think because 'DISPLAY=:0' requires an X server already running, but as I said earlier, the Raspian 'lite' distro does not have this running.

So now to how to get this working. What is needed is some sort of X server environment for claws-mail to run inside. This can be a 'dummy' X server such as 'xvfb' (X Virtual Frame Buffer), which was created for testing the X server away from specific hardware. To install:
sudo apt-get install xvfb
..This also installs an envelope program 'xvfb-run' which sets up the virtual frame buffer, and passes the DISPLAY reference to the application to run. In this case DISPLAY defaults to ':99'.
So my crontab entry now becomes:
*/10 * * * * xvfb-run claws-mail --receive-all >> /home/username/claws-mail.log 2>&1
..where the postamble ">> /home/username/claws-mail.log 2>&1" catches any error messages to a file 'claws-mail.log' (alter 'username' to your own login dir).

After ten minutes, typing:
ps -aux | grep claws-mail
..shows claws-mail running as a background daemon, attached to my username.

Typing:
claws-mail --status inbox
..returns three numbers: emails new, emails unread, emails total, (in the 'inbox' folder).

Job done, or nearly so. Typing the normal invocation:
claws-mail
..returns: Claws Mail is already running on display localhost:11.0.
(also sometimes localhost:99.0)
i.e. it locks me out! Which is exactly what I want at this moment, I do not want two instances running, both able write changes to the Mailbox file heirachy. So I need to first kill the crontab-vxfb-run instance, then start the new instance alone.

Refer to: 'man xvfb' and 'man xvfb-run'
also: https://unix.stackexchange.com/question ... ess-device

User avatar
sayhello
Posts: 102
Joined: Sat Mar 05, 2016 1:02 pm

Re: claws-mail automation

Sun Dec 13, 2020 11:44 am

hi there

many thanks for raising this great topic. i am really interested in this question too.
So now to how to get this working. What is needed is some sort of X server environment for claws-mail to run inside. This can be a 'dummy' X server such as 'xvfb' (X Virtual Frame Buffer), which was created for testing the X server away from specific hardware. To install:
sudo apt-get install xvfb
..This also installs an envelope program 'xvfb-run' which sets up the virtual frame buffer, and passes the DISPLAY reference to the application to run. In this case DISPLAY defaults to ':99'.
So my crontab entry now becomes:
*/10 * * * * xvfb-run claws-mail --receive-all >> /home/username/claws-mail.log 2>&1
..where the postamble ">> /home/username/claws-mail.log 2>&1" catches any error messages to a file 'claws-mail.log' (alter 'username' to your own login dir).

After ten minutes, typing:
ps -aux | grep claws-mail
..shows claws-mail running as a background daemon, attached to my username.
are there any further ideas on this - how to achieve this?!


love to hear from you

Return to “General discussion”