Since I switched from KDE to XFCE, I had to setup everything again in order to get the functionality I was getting through KDE’s widgets and other tools. I got most of it through the XFCE panel’s widgets and Conky, but for some reason, the XFCE’s email checker doesn’t work for me. I am setting it up and seems to connect, but there are no notifications coming. No errors are shown in the logs, so I guess it might be either a small bug or it finds it hard for some reason to cooperate with my server.
To cut the long story short, I ended up using the following python script for doing the work. It is a ‘quick and dirty’ solution. I ‘m no python expert so there is high enough possibility there is some nonsense there! To use it, you will need of course to put your real username, password and imap server address (e.g. your gmail).
import imaplib import re import time import subprocess ## enter your account details bellow! imapServer = "imap.server.com" port = "993" username = "yourUserName" password = "yourPassword" ##how often to check? give interval in seconds! Checking too often might affect performance and stability. checkIntevaral = 120 Mailbox = imaplib.IMAP4_SSL(imapServer, port) rc,resp = Mailbox.login(username,password) if rc == 'OK': print("Connected to mail-server "+imapServer) rc, message = Mailbox.status('INBOX', "(UNSEEN)") unreadCount = int(re.search("UNSEEN (\d+)",str( message)).group(1)) oldValue = 0 file = open("/tmp/mailnotify.tmp", "w+") file.write(str(unreadCount)) file.close while(1): rc, message = Mailbox.status('INBOX', "(UNSEEN)") unreadCount = int(re.search("UNSEEN (\d+)",str( message)).group(1)) file = open("/tmp/mailnotify.tmp", "r+") oldValue = int(file.readline()) file.close() if (unreadCount>oldValue): subprocess.call(["notify-send", "-u", "low", "-t", "5000", "New email!" ,"You have "+str(unreadCount)+" unread "+ "emails!" if unreadCount > 1 else "email!", "--icon=email"]) if oldValue != unreadCount: file = open("/tmp/mailnotify.tmp", "w+") file.write(str(unreadCount)) file.close() time.sleep(checkIntevaral) else : print('Fail to connect') Mailbox.logout() file.remove()
Save this as checkMail.py and run is through your terminal:
When you run it like that, if it connects successfully it will return a success message, otherwise you’ll get an error.
When you get a new email, the script will send a desktop notification informing you how many unread emails you have in your inbox.The python script will store the number of unread emails to a temporary file in your /tmp/ directory, called “mailnotify.tmp”. If you use conky, like I do, it is then easy to put the two things together and have a counter on your desktop, like the following:
There you go, you have email notifications and unread emails counter on your desktop!
PS: I am no Python expert and as I said, the script is a “quick and dirty” one! If you notice something weird, or have suggestions or improvements, please throw a comment!