Webmail allows you to easily access your e-mails anytime and anywhere if you have a device with an internet access and web browser. You can easily create a webmail using Roundcube.
Roundcube Webmail is a browser-based multilingual IMAP client with an application-like user interface. It is a free and open source webmail solution with a desktop-like user interface which is easy to install and configure. It runs on a standard LAMPP server. It provides complete functionality as found in an email client which includes an address book, folder management, MIME support, message searching and spell checking. Roundcube includes other sophisticated open-source libraries such as PEAR, an IMAP library derived from IlohaMail the TinyMCE rich text editor, Googiespell library for spell checking or the WasHTML sanitizer by Frederic Motte. Roundcube Webmail is written in PHP and requires the MySQL, PostgreSQL or SQLite database. It’s plugin API it is easily extendable and the user interface is fully customizable using skins which are pure XHTML and CSS 2.
Let us first understand how an email actually work in order to understand where Roundcube fits in your email infrastructure.
Mail User Agent (MUA) -A user interacts with this interface to view and send email.
Mail Transfer Agent (MTA)- This transfers an email from the sender to the recipient.
Mail delivery agent (MDA)– It receives emails from MTAs and stores them.
Simple Mail Transfer Protocol (SMTP)- It is the protocol MUAs use to send mail to MTAs.
Internet Message Access Protocol (IMAP)– It is a protocol that MDAs use to deliver mail to MUAs.
When an email is sent, Mail User Agent transfers it to email server’s Mail Transfer Agent using Simple Mail Transfer protocol. Then the recipient’s Mail Transfer Agent will receive the email after several hops and transfer it to their Mail Delivery Agent using Internet Message Access protocol. Then your recipient can view the email using their MUA of choice.
Roundcube acts as a Mail User Agent and not as a Mail Transfer Agent. We would still need a service to manage emails if we use it. For this we can use our own mail servers or use public email services like Gmail or hosted email from Internet Service Provider.
Before we get started –
You will need the following:
- One Ubuntu 16.04 server.
- Install LAMP Stack packages.
- An IMAP-based email server. We will use Gmail to get service to manage emails in the following instructions.
- Familiarize yourself with the IMAP and SMTP settings for your email server.
1.Start with Installing Dependencies
We first need to install Roundcube’s dependencies and configure PHP. After Roundcube’s installation we can use it’s dependency check page to ensure that everything is set up as required
To install all dependencies, update your package index as follows :
sudo apt-get update
sudo apt-get install php-xml php-mbstring php-intl php-zip php-pear zip unzip git composer
Enabling PHP libraries :
sudo nano /etc/php/7.0/apache2/php.ini
Changes that are needed can be enabled by uncommenting the lines.
Look for the lines which contains commented lines(commented lines start with a ; semicolon) beginning with extension=.
Uncomment the lines for the php_mbstring.dll and php_xmlrpc.dll extensions.
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_exif.dll ; Must be after mbstring as it depends on it
;extension=php_mysqli.dll
. . .
;extension=php_sqlite3.dll
;extension=php_tidy.dll
extension=php_xmlrpc.dll
;extension=php_xsl.dll
After this add extension=dom.so at the end of the extension block.
extension=php_xmlrpc.dll
;extension=php_xsl.dll
extension=dom.so
Other changed needed in this file are:
- Change time zone by first uncommenting date.timezone line and adding your own timezone in it.( Refer to PHP’s timezone page)
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = “Asia/Tokyo”
- Find and uncomment the line post_max_size and set the size of the whole email which includes attachments.
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 18M
- Find and uncomment this upload_max_filesize line and change uploading attachment size fromto 2MB to any amount you want,(Email servers usually limit the total attachment size to 10MB). Set this up to a lesser value than used in setting size of whole email.
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 12M
- Find this mbstring.func_overload and uncomment it, and checl it’s value is set to 0. This enables support for multi-byte string functions.
mbstring.func_overload = 0
Save this file and close it.
Your server is now set up with a LAMP stack, Roundcube’s dependencies, and the necessary PHP configuration.
2. Download Roundcube
Install Roundcube from source or package. To ensure latest version install from source.
Navigate to the https://roundcube.net/download/ and in the Stable version section find the Complete package. Right click the Download button and select Copy Link Address.
Use the address with wget to download the Roundcube tarball on the server.
wget https://github.com/roundcube/roundcubemail/releases/download/1.3.0/roundcubemail-1.3.0-complete.tar.gz
To decompress the Roundcube archive use
tar -xvzf roundcubemail-1.3.0-complete.tar.gz
Usage of eah flag in the argument of tar:
- The z flag tells tar to not only remove the tar wrapper but to decompress the archive using gzip. We know the file is compressed with gzip because the file extension has .gz on the end.
- The f flag stands for file. This must be the last flag because tar uses whatever immediately follows it as the file to be extracted.
- The x flag is for extract.
- The v flag is for verbose, which tells tar to print the path and name of every file extracted.
Next, move the decompressed directory to /var/www and rename it to roundcube.
sudo mv roundcubemail-1.3.0 /var/www/roundcube
At last, change the owner and group to www-data, and change the permissions to read and write for the owner and group, but read only for everyone else.
sudo chown -R www-data:www-data /var/www/roundcube/
sudo chmod 775 /var/www/roundcube/temp/ /var/www/roundcube/logs/
Roundcube’s code is now downloaded with updated location and permissions. Next is to configure Apache.
3. Apache Configuration
In order configure Apache we need to edit virtual host file. Virtual hosts are a feature that allow Apache to host multiple sites on the same server.
Each .conf file located under /etc/apache2/sites-available/ represent a different site. First create a virtual host file here for Roundcube, then tell Apache about it so it can make it available through a browser.
First, copy the default configuration file to use as starting point for the new file.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/roundcube.conf
Open the file with your text editor.
sudo nano /etc/apache2/sites-available/roundcube.conf
In the VirtualHost block, change the following directives:
- The ServerName tells Apache which domain to listen to. This should be your server IP address or domain name, if you’re using one.
- DocumentRoot specifies where to send traffic when it comes in. In our case, we should send it to Roundcube at /var/www/roundcube.
- ServerAdmin lets you specify an contact email address for any issues with Apache. We aren’t configuring Apache to do that in this tutorial, but it’s best practice to include it anyway.
- ErrorLog and CustomLog, the two logging lines, defines where to save successful connection logs and error logs for this site. We need to give the error logs specific names so if there is an issue the logs specific to this site are easily found.
Then, you’ll add a new Directory block which tells Apache what to do with the Roundcube directory. The first word in each line of a Directory block is the configuration name followed by the actual configuration options.
- Options -Indexes tells Apache to display a warning if it can’t find an index.html or index.phpfile. By default, it will list the contents of the directory instead.
- AllowOverride All tells Apache that if a local .htaccess file is found, any options in that file override the global settings in this file.
- Order allow,deny tells Apache first to allow matching clients access to the site, and then to deny any that don’t match.
- allow from all is a followup to the Order line. It defines what type of client is allowed, which is any in our case.
<VirtualHost *:80>
ServerName your_server_ip_or_domain
DocumentRoot /var/www/roundcube
ServerAdmin sammy@example.com
ErrorLog ${APACHE_LOG_DIR}/roundcube-error.log
CustomLog ${APACHE_LOG_DIR}/roundcube-access.log combined
<Directory /var/www/roundcube>
Options -Indexes
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Save and close the file.
To stop hosting the default site by Apache :
sudo a2dissite 000-default
To start hosting the Roundcube site (do not to include the .conf extension)
sudo a2ensite roundcube
Enable the mod_rewrite Apache module, which Roundcube requires.
sudo a2enmod rewrite
At the end, restart Apache, which will make the Roundcube installation accessible.
sudo apache2ctl restart
In the last step of the installation process is to configure the database so that Roundcube can store its app-specific data.
4. MySQL Configuration
Connecting to the MySQL interactive shell. This command tells MySQL to verify as the user (-u) root and that we’ll give a password (-p).
mysql -u root -p
After this enter your MySQL password.
Now we will complete the following steps in the mysql shell :
First we create database using the following command :
CREATE DATABASE roundcubemail /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
Creating a user and connecting to localhost changing to a secure password :
CREATE USER ’roundcube’@’localhost’ IDENTIFIED BY ‘password‘;
Grant all the required permissions to ‘roundcube’..
GRANT ALL PRIVILEGES ON roundcubemail.* to ’roundcube’@’localhost’;
Save the changes made and exit MySQL shell.
FLUSH PRIVILEGES;
EXIT;
Setting up structure to tell Roundcube where to save information. The Roundcube install provides a file that’ll configure the database for us, so we don’t have to do it by hand.
The following command tells MySQL to use our newly created user to read in a file /var/www/roundcube/SQL/mysql.initial.sql and apply the configuration to the database roundcubemail.
mysql -u roundcube -p roundcubemail < /var/www/roundcube/SQL/mysql.initial.sql
You’ll be prompted to enter the roundcube user’s password.
Setting up the database in this way prepares it for Roundcube’s use and also allows us to verify that we have the right permissions. If all was successful, you’ll receive no feedback and be back at the command prompt. Then we’re ready to tell Roundcube our email settings and finalize the installation.
5. Roundcube Configuration
To complete our installation, we need to visit http://your_server_ip_or_domain/installer
There will be a green OK to the right of every line item if everything is setup properly, except for – the optional LDAP setting and every database line except MySQL.
If there is a NOT AVAILABLE next to any other line than those above mentioned, you will be required to install those dependencies. Roundcube provides a link for any missing dependency so you can figure out what to install.
After everything is set up, click the NEXT button at the end of the page..
The form on the next page, is divided into seven sections, which walks through generating the Roundcube configuration file. Below are the sections of the form we need to fill out. If a line from the form is excluded in the sections below, you can skip that line and leave it with the default settings.
In General configuration you should ensure that the following change is made:
- Tick the ip_check for higher security. It checks the client’s IP in session authorization.
Other changes that you can make in general configuration are:
- product_name : This can be anything you want and all references to “Roundcube” in text will be replaced with this name instead.
- support_url. This is a URL where users can get support for their Roundcube installation. It isn’t strictly needed, but it can be nice if Roundcube is being provided for a group of people who may need assistance. If you don’t have a dedicated help desk site, you can use an email address, like mailto:ronald@example.com.
- skin_logo: You can replace the Roundcube logo with this, which takes a URL to a PNG file (178px by 47px). If you are going to enable HTTPS then make sure the image URL is an HTTPS URL.
Leave other options to default values.
In Logging and Debugging section leave everything to its default value.
For Database Setup :
- Select MySQL from the Database type pull down menu.
- Enter localhost for the Database server.
- Enter the database name, roundcubemail, in the Database name field.
- Enter the database user, roundcube, in the Database user name field.
- In Database password field, enter the password you defined when creating the database in Step 4.
- db_prefix, isn’t required unless you are with using a shared database with other apps. If so then enter something like, rc_.
For IMAP Settings:
Since we are using Gmail as service provider, it’s IMAP setting is given below, in case of other service provider you will provided with its imp settings by them
- In efault_host field enter the IMAP server URL. When using SSL connections, prefix the URL with ssl:// instead of https://.
- For Gmail, enter ssl://imap.gmail.com.
Following are other IMAP settings:
- In the default_port, which is the IMAP server port. SSL and non-SSL connections will use different ports, so make sure to use the SSL port. Gmail’s SSL IMAP port uses 993.
- Make sure the auto_create_user check box is selected. If it’s unchecked, Roundcube won’t create a user in its own database, which will prevent you from logging in.
- The field username_domain iis optional for email providers that use a full email address as the username. This field is optional. Entering a domain — not the full email — will allow you to login to Roundcube with just your name, before the @, instead of the whole email. For example, entering gmail.com in the field will allow user@gmail.com to log into Roundcube with user.
- Leave *_mbox fields, like sent_mbox, to its default values
In SMTP Settings like the IMAP server section, we’ll use the SSL URL and port, and Gmail for reference.
- Enter the SMTP server address in the smtp_server field.
Gmail’s SMTP server is ssl://smtp.gmail.com.
- Enter the SSL SMTP server port in the smtp_port field.
The SSL port for Gmail is 465.
- Insmtp_user/smtp_pass, leave it blank and check the box next to Use the current IMAP username and password for SMTP authentication.if you want it to be same as IMAP username and password, otherwise enter a different user name and password.
- Check the smtp_log.
In Display settings & user preference, leave it to its default values.
In Plugins, all are optional but this feature is what makes Roundcube better than other, it make’s it easier and more secure..
Following are the plugins and their descriptions:
- archive: Provides an Archive button, similar to how Gmail works.
- newmail_notifier: Uses your browser notification system to alert you to new emails.
- hide_blockquote: Hides the quoted portion of replied emails to keep the UI cleaner.
- identity_select: If you have multiple email addresses (identities), it allows you to easily select them while composing an email
- emoticons: Simply makes it easier to use emoticons in emails.
- enigma: Allows GPG email encryption. We’ll go into detail on how to configure this in the next security tutorial.
- markasjunk: Allows marking an email as spam and have it moved to your Spam folder.
- filesystem_attachments: A core plugin to allow saving attachments to the Roundcube server temporarily when composing or saving a draft email.
Save your settings by pressing the UPDATE CONFIG button.
6.Testing
Now we will test the roundcube configuration.
After the updating of configuration, the page will refresh and you’ll see a yellow info box at the top of the page which says The config file was saved successfully into RCMAIL_CONFIG_DIR directory of your Roundcube installation.
Click on the CONTINUE button to test your configuration
If there are no errors, you’ll see a green OK marker on every line. If not, go back and double check what you entered.
To test the rest of the configuration, put in your IMAP and SMTP username and password in the Test SMTP config and Test IMAP config sections, then click Send test email and Check login, respectively. If a test is successful, the page will reload and you’ll see the green ‘OK’ under the section you tested.
In case Gmail’s 2 step authentication is enable generate an app specific password as Roundcube will not prompt for2 step authentication token.
Next Remove the Installer Directory so that no one can reconfigure or override it.
Go back into your SSH session and delete the directory
Sudo rm -rf /var/www/roundcube/installer
Now visit your Roundcube instance using your server’s IP or your domain name, log in, and check your email.
Conclusion
Now that you have installed Roundcube, you have your very own free, web-based email client similar to Google’s Gmail or Microsoft’s Hotmail. Users can access their email by navigating to https://webmail.example.com.
With Roundcube, you can have the feature set and appearance of a native desktop client with the flexibility of a webmail client. You have a fully functional installation now, but there are some additional steps you should take to make sure you’re fully secure (like adding HTTPS support and using GPG encryption for your email).
In addition, you can install new themes to enhance the look of your client and plugins to add new functionality.
0 Comments