Tuesday 29 November 2022

Setting up Rainloop webmail on Linux

I recently discovered that Fastmail does support offline mail reading, without a $60 extra fee!

I have Dovecot/Postfix setup so I decided to setup rainloop to provide webmail.

Rainloop is written in php and uses IMAP as a back end (it requires no database) and does not have to run on the same host as the IMAP server.

Setup instructions on https://www.rainloop.net/ are woeful, so I figured I'd contribute some better docs to my future-self.

Debian package requirements

apt-get -y install wget php apache2 php7.4-curl php7.4-xml

Install latest version from repository.rainloop.net

mkdir -p /var/www/rainloop
cd /var/www/rainloop
wget -qO- https://repository.rainloop.net/installer.php | php 
chown -R www-data:www-data .
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

This gives you bunch of scripts in /var/www/rainloop/rainloop/v/1.12.0/ and a data directory /var/www/rainloop/data. Apache/Nginx setup needs care not to expose /var/www/rainloop/data.
The most basic apache config is a follows.

	ServerName mail.myco.org
	<VirtualHost *:80>
		ServerAdmin webmaster@myco.org
		DocumentRoot /var/www/rainloop
		ErrorLog /var/log/apache2/error.log
		CustomLog /var/log/apache2/access.log combined
	</VirtualHost>

If you are using Debian, create this text file in /etc/apache2/sites-available/rainloop.conf and symlink to /etc/apache2/sites-enabled/rainloop.conf
Given that /data is shared by default you should probably remove directory indexing

rm /etc/apache2/mods-enabled/{autoindex.conf,autoindex.load}

and do make sure that .htaccess is observed.

The ./data directory is setup when you first access the rainloop admin GUI on http://myhost/?admin default user and password is admin / 12345.

Configuring the IMAP server is as simple as creating an .ini file in /var/www/rainloop/data/_data_/_default_/domains/

e.g. domains/myco.ini

imap_host = "mail.myco.org"
imap_port = 993
imap_secure = "SSL"
imap_short_login = On
smtp_host = "mail.myco.org"
smtp_port = 25
smtp_secure = "TLS"
smtp_short_login = On
smtp_auth = On
smtp_php_mail = Off
white_list = ""

A small amount of configuration is needed, the config values are generally self-explanatory.

Rainloop administrator GUI defaults to open on the Intenet with a well known username and password!

Change the admin user with

app_ini=$root_fs/var/www/rainloop/data/_data_/_default_/configs/application.ini
   
sed -i -e 's/^admin_login = *$/admin_login = "xxxadmin"/' $app_ini

Potentially change the URL too

sed -i -e 's/^admin_panel_key = *$/admin_panel_key = "xxxadmin"/' $app_ini

If you dont need the admin UI, the whole thing can be disabled which is probably safest.

sed -i -e 's/^allow_admin_panel = .*$/allow_admin_panel = Off/' $app_ini

All that remains is to setup HTTPS in Apache. I have Nginx handling TLS and proxy_pass to Apache.

/var/www/rainloop/data/_data_/_default_/configs/application.ini has other options to play with, including options for company branding and themes.

Rainloop has a mobile friendly UI but does not give you off-line mail reading, I'm using K-9 Mail from F-Droid.

In summary: Dovecot + Postfix + Rainloop gives me a completly free very modern and feature rich email stack.