A solution for email logging

We previously used Ben C's 'send email out via Google's SMTP server' to provide logging of emails.  However, this is not (because of various restrictions) a fully satisfactory solution - particularly if you run multiple practice locations.

We have now tested what appears to be a superior solution that uses an SMTP proxy which is part of a free program called EmailRelay (see http://emailrelay.sourceforge.net/ ). EmailRelay can be used both on Windows and unix systems, and can be used in a number of ways - it our case we run it as an SMTP proxy.

Essentially, instead of having OpenVPMS send mail to google’s smtp server (or anyone else’s SMTP server), you tell OpenVPMS to send it to the EmailRelay as follows:

 

EmailRelay is set to copy the email just prior to sending it off to the smtp server that you told it to use. The saved file is in ‘MIME’ format. The advantage is that this contains the complete mail message – including the attachments.  Being all text, this is human readable, but there is a lot of gobblydegook.

Now I said that EmailRelay copies the file.  In fact it does not – it calls a program or script that you supply and this can potentially do anything. For example it could look at the email to see whether it is an SMS message and if so, copy it to a specific folder. Or it could look at the first To Addressee and file in a folder of that name, or ….

In our case (running OpenVPMS on a Windows system), we need two other tools: one to search the saved emails for the one(s) you are looking for, and one to look at and perhaps process the saved emails.  We use WinGrep (see http://www.wingrep.com/ ) for the first and either Outlook Express [OE] (for Win 2003 Server) or Windows Live Mail [WLM] (for Win 2012 Server, Win 7 or 8) for the second.

WinGrep has the advantage that having found the text being searched for, it can launch a program to process the file.  If the saved emails have the extension .eml then Outlook Express/Windows Live Mail will happily open then and display the email and any attachments, and can then be used to print or forward the email as required.

The script used by EmailRelay is (for Windows) written in JavaScript [for unix you use a shell script]. For our use, I made the script copy the email so that the saved copy is in a file named aaa mmm.eml where aaa is the first To: addressee’s email address and mmm is the number of milliseconds since 1/1/1970 (which just serves to separate multiple emails to the one person) – so a mail to bloggs[at]gmail[dot]com would be in the file "bloggs[at]gmail[dot]com 1422681860646.eml".

The script (renamed from copymail.js to copymail.txt) is attached. (Note that this copes with the 'simple' bloggs[at]gmail[dot]com email addresses used by 1.7 - it needs ammending to cope with the Joe Bloggs<bloggs[at]gmail[dot]com> format that 1.8 can use.)

Finally a note about installing EmailRelay. When you install on Windows you get a GUI interface to configure it - and this builds the emailrelay-start.bat file. I found it easier to manually edit this file rather than use the GUI.  It consists on one single line. Ours is:

start "emailrelay" "C:\Program Files (x86)\emailrelay\emailrelay.exe" --client-auth "C:\Program Files (x86)\emailrelay\emailrelay.auth" --as-proxy smtp.netvigator.com:25 --pid-file "C:\Program Files (x86)\emailrelay\emailrelay.pid" --server-auth "C:\Program Files (x86)\emailrelay\emailrelay.auth" --spool-dir C:\Users\Administrator\WINDOWS\system32\spool\emailrelay --filter "C:\OpenVPMS\copymail.js" --syslog --verbose

The --verbose is useful when debugging. Remove it when things are running. Note that the filter script ( C:\OpenVPMS.copymail.js in the above) needs to be in a folder that has no spaces in its name (because of a bug that does not enclose its name in quotes when it is being invoked).

You will need to change the "smtp.netvigator.com:25" to match the SMTP server and port that you use.

The emailrelay.auth file is as follows:

#
# emailrelay.auth
#
# {server|client} <mechanism> <name> <secret>
#   mechanism = { CRAM-MD5 | LOGIN | APOP | NONE }
#
client LOGIN xxx[at]netvigator[dot]com p12345
server LOGIN openvpms openvpms

 

The client LOGIN line gives the user name and password to login to your real SMTP server, and the server LOGIN line gives the user name and password used by OpenVPMS to send email to the SMTP proxy.

 

SMS's and faxes. Since all our SMS messages go to 9999999[at]onewaysms[dot]asia (where 9999999 is the phone number and onewaysms.asia is our SMS provider) we can select all the SMS’s using the file mask *onewaysms*.eml – or all SMS’s to the phone number 98765432 by using the mask 98765432@onewaysms*.eml

Similarly, since we send faxes using an email-to-fax gateway at efaxsend.com, we can also log and look at the faxes sent.

Finally, since WinGrep can be made to search down through folders, there is no reason why we cannot split the archive by date – ie keep each year’s (or month’s) mail in a separate folder.

 

When I get around to updating the copymail.js script to handle "Joe Bloggs<bloggs[at]gmail[dot]com>" format addresses, I will post it here.

 

Note that while it might be nice to have the email logging built into OpenVPMS, we would need to add not only the actual logging (ie the work being done by the EmailRelay and filter script in the above solution), but also the ability to search for stuff and display/process emails.  The EmailRelay/WinGrep/OE|WLM solution, although needing some expertise to set up, works well. Users who run OpenVPMS on a unix server may find it better to have EmailRelay save the mime files on a shared drive (perhaps only accessible to certain users) so that users on a Windows box can use the WinGrep/OE|WLM components.

Regards, Tim G

Syndicate content