How to Host a Personal Email Server on Google Cloud (for Free!): Part V

Hosting Webmail with Roundcube

Lee Phillips
Geek Culture

--

Articles in this series

  1. Introduction & GCP Setup
  2. Configuring Postfix, Mailgun, & DNS Records
  3. Configuring Dovecot & Encryption
  4. Managing Virtual Mailboxes with MariaDB & Postfixadmin
  5. Hosting Webmail with Roundcube
  6. Filtering Spam with Rspamd & Sieve

If you have not read the previous articles in this series, please follow the links above to catch up. We now have our server running on GCP configured to send and receive email via the SMTP protocol and allow IMAP connections, while encrypting traffic with TLS. Our DNS records are configured properly to ensure email is delivered to & from us, and we are using virtual mailboxes so that there is no need for a local unix user for each mailbox. These are stored in a MariaDB database and managed using Postfixadmin via a web browser.

We have successfully connected from an email client, but what if we don’t have access to a personal device and need to access our mailbox? It sure would be handy to have a webmail client that we can access in our browser. Roundcube offers just that! It is a free, full-featured, open source webmail client written in PHP. On top of that, thanks to all the work we have already put in, it is going to be a piece of cake to add to our private email solution! Let’s get started.

Installing Roundcube

First, download the latest version of Roundcube.

wget https://github.com/roundcube/roundcubemail/releases/download/1.6.1/roundcubemail-1.6.1-complete.tar.gz

Extract the archive and move the content into the site’s root directory.

tar -xf roundcubemail-1.6.1-complete.tar.gz
sudo mv roundcubemail-1.6.1/* /var/www/mail/

Then, ensure that root owns the files. The exception being that www-data needs ownership of the temp/ and logs/ directories.

sudo chown -R root:root /var/www/mail/
sudo chown -R www-data:www-data /var/www/mail/temp/ /var/www/mail/logs/

We can now remove the default index file provided by Nginx.

sudo rm /var/www/mail/index.nginx-debian.html

Creating a Database and User for Roundcube

Roundcube needs a database to store user information separately from the virtual mailbox database we set up previously. We also need to create a user with proper permissions for Roundcube to access the database. Run mysql.

sudo mysql

Then, run the following commands to create the database and user with permissions. Replace password with a password of your choosing.

CREATE DATABASE roundcube;
CREATE USER roundcube@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON roundcube.* TO roundcube@localhost;
flush privileges;
exit;

Afterwards, import the initial tables provided by Roundcube into the database.

sudo mysql roundcube < /var/www/mail/SQL/mysql.initial.sql

Finishing Installation in the Browser

Now navigate to https://mail.example.com/installer to complete installation, replacing mail.example.com with your mail subdomain. If you’ve followed along with all of this series, you will see that we are missing three PHP extensions that Roundcube requires.

We can install them with the following command:

sudo apt install php-xml php-intl -y

After refreshing the page, we can now scroll down to the bottom and select NEXT to continue installation. For the most part, the default selections are fine, but if you want to customize your install further, you can learn more about the parameters here. We will have to edit a few sections though, starting with Database setup. Fill in with the details used to setup our database.

Next, we need to tell Roundcube to use secure IMAP & SMTP connections when communicating with Dovecot & Postfix. Enter the following in the IMAP Settings section, using your mail subdomain.

Then, configure the SMTP settings as follows.

We must use our subdomain here, but there is no reason to waste precious resources querying public DNS to find our own server! Let’s add a local DNS entry for our subdomain alongside localhost. Update the first line in /etc/hosts.

127.0.0.1       localhost mail.example.com

There are all kinds of great plugins to add functionality to Roundcube. Scroll down and check out the Plugins section to enable some before wrapping up.

NOTE: Some plugins may require additional steps to get up and running properly. A simple Google search for the plugin will easily find information on how to do so.

When you’re done, select CREATE CONFIG to create the configuration. As noted on the next page, we need to copy the configuration and save to /var/www/mail/config/config.inc.php.

Afterwards, click CONTINUE. Now we can test that our SMTP and IMAP configurations are correct.

If either test fails, you can go back and edit the configuration using the link at the top of the page. Once successful, be sure to remove the installer directory from our site’s root directory as it is a security risk.

sudo rm -R /var/www/mail/installer/

Now navigate to your subdomain in the browser (i.e. https://mail.example.com) and login.

Roundcube Webmail Interface

Conclusion

We can now access our mailbox from any device with a web browser! Let’s review how we accomplished this.

  • We downloaded Roundcube into our mail site’s root directory & set proper ownership on all files.
  • We created a database & user with correct permissions for Roundcube.
  • We followed the instructions provided by the Roundcube installer in our web browser, then removed the installer.
  • We also created a local DNS entry for our subdomain to prevent Roundcube from querying public DNS when communicating with Postfix & Dovecot.

Only one article left! Technically, if you feel that you are lucky enough to keep your email address out of the hands of evil-doers, then you could quit here. I warn you though, that is not the world we live in. Spam will eventually find your email server, tucked away in the cloud, and when it does, we will be ready for it. In the final article of this series, we will install Rspamd & Sieve in order to detect spam and reject it or send it to the Junk folder.

Thank you for reading! If you have found this series or article helpful, please clap and follow to be updated when the final piece is published.

--

--

Lee Phillips
Geek Culture

Software engineer. Flutter fanatic. I am here to share knowledge & inspire others to create great experiences.