Friday, 15 January 2010

Scan to email

I thought other GPs might find this useful:

Our photocpier has a scan function which transmits the scanned result onto a FTP server. Many multifunction scan/copy/printer can do this.

I rigged this up with my practice Linux server so that all scans get dumped in one directory there (was simple, just followed the copier's manual)

I then used incron to watch this directory and use a small script to email to the practice account all new files in there.

From there you can then forward them on via email to others who need them.

Works great. It already has made a difference to the way the practice manager works.





The incrontab looks like this:
/home/scans/public_html IN_CLOSE_WRITE /home/scans/bin/mail_attachment.sh $@/$#


The mailscript is simple too:

#!/bin/sh
echo "This is a scan from the photocopier" > /tmp/msg.txt
mutt -s "scans attached" -a $1 practicemail@localhost < /tmp/msg.txt

rm /tmp/msg.txt

Thursday, 13 August 2009

Setting up an IMAP server for a small GP practice

An IMAP mail server for a practice is a huge advantage over the usual MS Outlook or Thunderbird email client connecting directly from the Desktop to NHSnet. Most of us have very slow bandwidth, so downloading the same attachments again and again can be a serious hog on everyone's time and can stop others within the same practice getting on with what they need to get on with.

Further, if you, like us, have a practice account into which all email flows, rather than NHSnet's idea of a personal account for everyone, you do want that everyone has instantaneous access to the same emails.

Finally, given the small quota on the NHS net server we have to contend with, we all require some storage for older emails which might still be important. Preferably this storage is commonly accessible and searchable.

So, setting up a central email server which downloads the emails from NHSnet and then serves it to the various desktop computers is the right way forward.

There are in principle two ways of reading emails from a central server: The POP3 way and the IMAP way. You might still know POP3 from dial-up times. It means that your inbox on the server is read out and emails sucked over to your client. IMAP is a whole lot more comfortable - you can have lots of folders, sub folders and the server and client keep each other in sync. You can, if you wish only read the headlines out and leave heavy attachments on the server.

If you use for your practice server Ubuntu or Debian Linux then you are only a few steps away from this aim:

sudo apt-get install dovecot

Dovecot is a very comfortable IMAP and POP server.

After installing it, it will be more or less ready to run.

Start up your favourite editor and change following lines in the default /etc/dovecot.conf:
protocols = imap imaps

You will not need POP3, so disable it.

default_mail_env = maildir:/home/%u/Maildir

This will ensure that dovecot uses Maildir format for inbox and all other folders. The Maildir is stored in each users /home directory.

Dovecot installed in this way will serve email for every user registered as normal unix user on the server. there are ample ways of creating virtual users, but for a small practice this is probably OTT.

Wednesday, 12 August 2009

Using Getmail to get your NHSnet emails

Getmail is a small python script to download automatically emails from a variety of servers. Unlike fetchmail it is stable, easily configured and does not do your head in. Unlike fetchmail it does not run as a daemon, but requires to be called regularly by the user. I use crontab for this purpose.


My getmailrc looks like this:



[Our Mail]

[retriever]
type = SimplePOP3SSLRetriever
server = pop.nhs.net
username = xxxxxxx@nhs.net
password = SECRET_PASSWORD

[destination]
type = Maildir
path = ~/Maildir/

[options]
verbose = 0
read_all = False
delete_after = 10
delievered_to = True
message_log = ~/.getmail/log


Important is the delete_after option - this will keep your emails for another 10 days on the NHS net webserver, allowing you to check your emails via webmail when outside of the practice.

I am using the pop retriever. There is the option of using an imap retriever, but I am not sure if this will really bring any benefit.


My crontab looks like this


0,10,20,30,40,50 * * * * getmail --rcfile /home/mail/.getmail/getmailrc

This means that my account is checked every 10 minutes.

If you have a full NHS net account, run getmail once directly from the commandline to download the bulk. Start your crontab only after you have downloaded everything the first time. Otherwise you will get a mess of dublicate emails and very slow downloads

Half a mailserver (part 1)

NHS net limits us nowadays to 50-200 megabyte. Not a lot considering all those PCT adminroids who will without further thought send out emails with 5 megabyte attachments and more.

What is there to do?

Create your own mailserver in the practice! Half a mailserver to be accurate.

A mail server will enable you to store all NHSnet mail and serve it within the practice to all client computers. It will make archiving easy and allow you to filter out the ubiquitous garbage we receive and conserve the meagre bandwidth most of us enjoy on N3. Massive attachments are downloaded once into the practice and then, if re-read, will only require reloading within your own LAN.

Half a mail server?

Yes! A proper mail server is capable of receiving and sending emails and serving it or distributing it to the various local recipients. The sending bit is what would create difficulties for you with your NHS IT "support". We are not supposed to mess with the wider NHS network. Sending emails via your own email server would seem too close to comfort for most NHS IT "workers". So we cut that one out.

So, receiving emails and local distribution and serving is what we will require.

This will require three things:

  1. A Linux server on your LAN

  2. Dovecot

  3. getmail


Most Linux distributions are perfectly capable of doing this. I prefer for my practice Ubuntu or Debian, but this is because I know these well.

Dovecot is a very capable IMAP and POP server which comes with most Linux distributions as an easily installible package.

Getmail is a small but equally very capable programme which allows downloading emails from a variety of sources (for us this will be NHSnet).

More later

Configuring Thunderbird for NHS net

Since the migration of NHS net to Microsoft Exchange much of the previous functionality of NHSnet is gone lost. Not that it ever was a very good email service, but at least it was standard compliant. Now not anymore.

Anyhow, if you want to configure your Thunderbird (or any other proper email client) for NHS net, be aware this will only work within the N3 network.

Outside of the N3 network you have to use the rather awful Outlook Web Access.

Your settings:

imap.nhs.net (port 993)
TLS enabled
login name: xxxxx@nhs.net (do not forget the "@nhs.net")

send.nhs.net (port 587)
TLS enabled
login name as above


The imap server appears to be rather flaky and frequently loses connection. This leads unfortunately also to relatively frequent lock-outs. Be aware of that.