[2019-11-26]

Webmail using Roundcube

This page deals with the installation of Roundcube as a web mail interface. Roundcube is the software that was also used in the previous versions of this guide. So if your users are used to it… just stay with it.

If my spare time allows it this guide will be extended by alternative mail clients like Horde, Rainloop and Nextcloud.

Installation

Start by installing the software packages:

apt install roundcube roundcube-plugins roundcube-plugins-extra roundcube-mysql

Roundcube stores user settings in the database. So you will get asked to set up database access:

Or course choose mysql when asked:

When asked for a password just press ENTER.

Configure Apache

To get Apache to serve the Roundcube application you need to edit the /etc/apache2/sites-available/webmail.example.org-https.conf file. I suggest you change the DocumentRoot line to:

DocumentRoot /var/lib/roundcube

Also add this line within the same VirtualHost section to add a couple of prepared security settings:

Include /etc/roundcube/apache.conf

And as usual Apache needs to be restarted after the configuration change:

systemctl restart apache2

Limit access to localhost

The main configuration file of Roundcube is located at /etc/roundcube/config.inc.php. Feel free to customize the file. However I suggest that you make these changes:

$config['default_host'] = 'tls://webmail.example.org';

If you do not set the default_host here then Roundcube will ask the user for the name of the mail server at login. We don’t want that.

Also for sending emails you should use the same submission port as other email clients use:

$config['smtp_server'] = 'tls://webmail.example.org';
$config['smtp_port'] = 587;

So now when your users enter https://webmail.example.org/ in their browser they will get the Roundcube webmail application. Voila. Webmail works.

Username == email address

Keep in mind that we are using the email address as the account name of the user. So when logging in please enter the email address as the user name. E.g. ‘john@example.org’ and password ‘summersun’.

Plugins

Roundcube comes with various plugins that you can offer your users. I suggest to use at least these two:

  • password: Let the user change their access password.
  • managesieve: Let the user manage rules that apply to incoming email. They can move mails to specific folders automatically for example.

Again edit the /etc/roundcube/config.inc.php file and look for the plugins configuration. To enable my recommended plugins change it to:

$config['plugins'] = array(
     'managesieve',
     'password',
 );

password plugin

Plugins are configured through files located in the /etc/roundcube/plugins directory. Let’s begin with the password plugin. Edit the /etc/roundcube/plugins/password/config.inc.php file.

Oops, that file looks pretty empty. But it refers us to an example file at /usr/share/roundcube/plugins/password/config.inc.php.dist. There are many different methods to let users change their passwords. As we store that information in the SQL database that is the part we need to set up.

Remove the empty definition line of $config from your config.inc.php file. Let’s go through the required settings one by one:

  • $config['password_driver'] = 'sql';
    Simple. Use SQL as a backend.
  • $config['password_minimum_length'] = 12;
    Allow no passwords shorter than 12 characters. I consider longer passwords more secure than short passwords with weird characters. You can even choose a larger minimum.
  • $config['password_force_save'] = true;
    This will overwrite the password in the database even if it hasn’t changed. It helps us improve the strength of the password hash even if the user chooses to keep his old password.
  • $config['password_algorithm'] = 'dovecot';
    Make Roundcube use the below dovecot-based settings.
  • $config['password_dovecotpw'] = '/usr/bin/doveadm pw -s BLF-CRYPT';
    The command to create a hash for a new password that the user entered.
  • $config['password_dovecotpw_method'] = 'BLF-CRYPT';
    Add a prefix to the password hash that explicitly designates it as a bcrypt hash. That makes it easy if in the future we want to use other hashing algorithms.
  • $config['password_dovecotpw_with_method'] = true;
    Enable the above setting.
  • $config['password_db_dsn'] = 'mysql://mailadmin:gefk6lA2brMOeb8eR5WYaMEdKDQfnF@localhost/mailserver';
    Connection information for the local database. Use your own password for the mailadmin database user here. We cannot use the restricted mailserver user because we have to actually change data in the database.
  • $config['password_query'] = "UPDATE virtual_users SET password=%D WHERE email=%u";
    The SQL query that is run to write the new password hash into the database. %D is a placeholder for the new password hash. And %u is obviously the email address.

Try it. Log into Roundcube as ‘john@example.org’ with password ‘summersun’. Go to the Settings. Choose Password. Enter a new password twice. You should get a success message at the bottom right (yeah, it’s a bit hidden). Now logout and login with the new password. Does it work? Great.

sieve plugin

Sieve is used for server-side rules. Dovecot executes these rules every time a new email comes in. Of course every mailbox can have its own rules. To manage sieve rules Dovecot offers the managesieve interface that you enabled earlier. So we just need to tell Roundcube how to reach it.

The configuration file for Roundcube’s managesieve plugin is found at /etc/roundcube/plugins/managesieve/config.inc.php. Edit the file and again remove the empty or comment the $config line. You can again find all possible configuration options in the /usr/share/roundcube/plugins/managesieve/config.inc.php.dist file.

This time just one setting is required to tell Roundcube which server to talk to:

$config['managesieve_host'] = 'localhost';

Sieve rules are stored in a special syntax on the server. This is an example that moves all incoming emails to the test folder if it contains “test” in the mail’s subject line:

require ["fileinto"];
if header :contains "subject" "test"
{
  fileinto "INBOX.test";
}

But hardly anyone manages rules like that. Roundcube’s rule editor is more user-friendly.

Try adding a sieve rule for john@example.org in Roundcube. If it works you will find the machine-readable sieve code at /var/vmail/example.org/john/sieve/roundcube.sieve.

42 thoughts on “Webmail using Roundcube

  • 2019-12-30 at 21:25
    Permalink

    For completeness, a note to restart Apache should be added – otherwise the changed DocumentRoot directive is not in effect 🙂

    Reply
    • 2019-12-31 at 11:50
      Permalink

      Indeed. Thanks. Added.

      Reply
  • 2020-01-02 at 21:38
    Permalink

    …just in case you are struggling with the same “Could not save new password. Encryption function missing.” error as I did:

    Find the “disable_functions” statement in your php.ini file and check whether the “proc_open” function is listed there. In my case it was. As a result, the subprocess, which is supposed to calculate hash of the new password, could not be spawned properly. The “[…] proc_open() has been disabled for security reasons […]” message in /var/log/roundcube/errors pointed me in that direction.

    Reply
    • 2020-04-09 at 14:37
      Permalink

      I am keep getting this error “Could not save new password. Encryption function missing” even though disable_functions are clear (everything is allowed). What’s wrong with this plugin?

      Reply
      • 2020-04-12 at 15:33
        Permalink

        After few minutes of debugging it turned out to be a problem with permissions for /etc/dovecot/conf.d/90-sieve.conf. Update password function is executed as www-data user which had no permissions to read above file.

        Reply
        • 2020-04-14 at 21:20
          Permalink

          Add the same issue, in fact several files in dovecot conf.d were not accessible by www-data user.
          Troubleshooted using :
          # su – www-data -s /bin/bash
          # doveadm pw -s BLF-CRYPT -p secret
          this produced 2 errors :
          1. doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/10-tcpwrapper.conf line 0: Couldn’t open include file /etc/dovecot/conf.d/10-ssl.conf: Permission denied
          and
          2. Error: net_connect_unix(/var/run/dovecot/stats-writer) failed: Permission denied

          both can be solved by setting correct perms

          Reply
          • 2020-04-14 at 21:21
            Permalink

            s/Add/Had/ 🙂

          • 2020-04-19 at 21:04
            Permalink

            I also think that definition in cfg /usr/share/roundcube/plugins/password/password.php file is incorrect:

            $config[‘password_dovecotpw’] = ‘/usr/bin/doveadm pw -s BLF-CRYPT’;

            because by looking at /usr/share/roundcube/plugins/password/password.php file we see following section:
            case ‘dovecot’:
            $pipe = proc_open(“$dovecotpw -s ‘$method'”, $spec, $pipes);

            But it somehow works 😉 Weird.

          • 2020-04-19 at 21:10
            Permalink

            Oh, I meant

            I also think that definition in cfg /etc/roundcube/plugins/password/config.inc.php file is incorrect:

  • 2020-01-04 at 04:37
    Permalink

    In case you edit the php files and the screen comes up empty, take a look in /var/log/apache2/error.log – it always show some clue. My mistake was look into /var/lib/roundcube/logs

    Reply
  • 2020-01-06 at 00:03
    Permalink

    Hello Christoph,

    Thank you for the great tutorials for many years.

    You wrote to set:
    $config[‘smtp_host’] = ‘tls://webmail.example.org’;
    I don’t find that in my roundcube config. I did find:
    $config[‘smtp_server’] = ‘localhost’;

    I guess it is probably the same but maybe you can confirm that?

    Reply
    • 2020-01-07 at 08:09
      Permalink

      Oops, I mixed up default_host and smtp_server. Thanks for spotting.

      Reply
  • 2020-01-06 at 03:25
    Permalink

    $config[‘smtp_server’]=’tls://webmail.example.org’ works for me.

    Reply
  • 2020-01-12 at 22:41
    Permalink

    The test-user is ‘john@example.org’, not ‘john@example.com’.

    Reply
    • 2020-01-12 at 23:26
      Permalink

      Yes – at this moment I also stopped and looked for where I have something wrong entered 🙂
      Great tutorial – many thanks!
      I have several mail servers on Deban without mysql but now I am happy to read and set up a new server. Many thanks for your work.

      Reply
    • 2020-01-14 at 12:03
      Permalink

      Ouch. Thanks. Fixed.

      Reply
  • 2020-05-11 at 11:50
    Permalink

    Just a remark… My debian installer enabled mpm_event by default for apache2, which is not compatible with PHP. So, had to:

    a2dismod mpm_event
    a2enmod mpm_prefork
    a2enmod mpm_php7.3
    systemctl restart apache2

    Reply
  • 2020-05-11 at 12:03
    Permalink

    Also, I think www-data needs read privileges for the config.inc.php and debian-db.php file. So maybe:

    chgrp www-data config.inc.php
    chgrp www-data debian-db.php
    chmod g+x config.inc.php
    chmod g+x debian-db.php

    Reply
  • 2020-05-15 at 13:14
    Permalink

    Apologies, for nit-picking yet again.

    Under ‘Limiting access to localhost’ both the variables are set to point to the external, actual domain name.

    I am just wondering, whether I can get away with jus setting ‘tls://localhost’, making the multi-domain hosting yet one bit easier.

    Reply
    • 2020-05-15 at 13:16
      Permalink

      And, yes, in fact, then we don’t even need TLS technically, but I reckon, otherwise the auth might not be triggered.

      Reply
  • 2020-06-05 at 00:42
    Permalink

    Just for the record: I’ve tried it, and it works fine with just plain ‘localhost’ for both ‘default_host’ and ‘smtp_server’. Also cross-checked with the previous tutorials, and those suggest just simply ‘localhost’.

    Reply
    • 2020-06-05 at 09:16
      Permalink

      Correction: IMAP will work, but sending will fail, as we only accept AUTH on TLS.

      Reply
  • 2020-06-12 at 02:07
    Permalink

    Further to Stephane Prunier’s comment about /var/run/dovecot/stats-writer, it is the subject of https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=903161 which was unresolved on 12 Jun 2020.

    Several solutions have been proposed. None of the solutions which do not required modifying a non-configuration file installed by package are pretty. Perhaps the least ugly solution is to edit /etc/dovecot/conf.d/10-master.conf and add
    unix_listener stats-writer {
    group = dovecot
    mode = 0666
    user = root
    }

    Reply
  • 2020-06-12 at 02:18
    Permalink

    Correction. The extra lines must be
    service stats {
    unix_listener stats-writer {
    group = dovecot
    mode = 0666
    user = root
    }
    }

    Reply
  • 2020-06-12 at 02:20
    Permalink

    Further to Stephane Prunier’s comment about /var/run/dovecot/stats-writer, it is the subject of https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=903161 which was unresolved on 12 Jun 2020.

    Several solutions have been proposed. None of the solutions which do not require modifying a non-configuration file installed by package are pretty. Perhaps the least ugly solution is to edit /etc/dovecot/conf.d/10-master.conf and add

    service stats {
    unix_listener stats-writer {
    group = dovecot
    mode = 0666
    user = root
    }
    }

    Reply
  • 2020-06-12 at 02:21
    Permalink

    Correction. The additional lines should be

    service stats {
    unix_listener stats-writer {
    group = dovecot
    mode = 0666
    user = root
    }
    }

    Reply
  • 2020-06-22 at 18:43
    Permalink

    If I use the purchased certificate and add to 10-ssl.conf (wildcard fullchain.crt privkey.key) roundcube has no connection to the server.

    Reply
  • 2020-08-05 at 06:43
    Permalink

    Everything works fine besides managesieve filters. Vacation message doesn’t sent email. I should something change in 20-managesieve.conf or it should works with default configuration?

    Reply
    • 2020-08-05 at 10:16
      Permalink

      Solved. I forgot add line below
      mail_plugins = $mail_plugins sieve

      Reply
  • 2020-08-27 at 11:03
    Permalink

    Hi, am really stuck with roundcube. I log in as a user, but when I check settings, emails. user interface, etc. It just sits stuck on “refused to connect.” on the right panel or “Loading”, but just does not load.

    Checked in /var/log, all logs, and nothing of interest. I followed some of the advice in the comments to no avail.

    Am php7.3, latest install on everything else. I don’t suspect a guide issue as it looks like others have got this going. This section of the guide is straightforward, so, hopefully can eliminate the nut on the end of the keyboard as an issue.

    Any pointers or solutions will be much appretiated.

    Reply
    • 2020-08-28 at 22:47
      Permalink

      Have you verified your firewall is accepting the appropriate ports? That’s my usual issue when I get the “no response” and/or “refused” errors.

      Reply
      • 2020-09-03 at 13:54
        Permalink

        Roughly guessing its the way I set my subdomain up. This is out of my area of expertise.
        ?_task=mail&_token=hw3j31ahPz0MeymXmxJ1bEg9V7Fn47Xh:1 Refused to display ‘https://WHEREEVER.com/skins/larry/watermark.html’ in a frame because it set ‘X-Frame-Options’ to

        Reply
      • 2020-09-03 at 15:38
        Permalink

        I think this is ok.

        ufw status
        Status: active

        To Action From
        — —— —-
        22/tcp ALLOW Anywhere
        25 ALLOW Anywhere
        443 ALLOW Anywhere
        80 ALLOW Anywhere
        3306 DENY Anywhere
        110 ALLOW Anywhere
        143 ALLOW Anywhere
        993 ALLOW Anywhere
        995 ALLOW Anywhere
        465 ALLOW Anywhere
        587 ALLOW Anywhere
        24 ALLOW Anywhere
        4190 ALLOW Anywhere
        51074 ALLOW Anywhere
        22/tcp (v6) ALLOW Anywhere (v6)
        25 (v6) ALLOW Anywhere (v6)
        443 (v6) ALLOW Anywhere (v6)
        80 (v6) ALLOW Anywhere (v6)
        3306 (v6) DENY Anywhere (v6)
        110 (v6) ALLOW Anywhere (v6)
        143 (v6) ALLOW Anywhere (v6)
        993 (v6) ALLOW Anywhere (v6)
        995 (v6) ALLOW Anywhere (v6)
        465 (v6) ALLOW Anywhere (v6)
        587 (v6) ALLOW Anywhere (v6)
        24 (v6) ALLOW Anywhere (v6)
        4190 (v6) ALLOW Anywhere (v6)
        51074 (v6) ALLOW Anywhere (v6)

        Reply
        • 2020-10-03 at 08:47
          Permalink

          I got it all working. Don’t ask me how!!!!

          Thanks for the guide.

          My advise to others is take your time. Be carefull with your cut and paste and your passwords, its so easy to mess something up.

          Also, your server, if you are renting it from someone, they may have additional firewall restrictions which you may not be aware of. This will trip you up!

          Good luck.

          p.s. Still some issues with Thuderbird, but am sure it can be sorted, eventually….

          Reply
  • 2020-08-28 at 22:33
    Permalink

    For the Roundcube Password plugin, I’d suggest adding the following setting the config.inc.php file:

    $config[‘password_confirm_current’] = true;

    This will cause Roundcube to require your current password before allowing you to change to a new one.

    Reply
  • 2020-10-04 at 15:52
    Permalink

    Hi Cristoph,
    I try to test roundcube, but when I insert username and password (in mutt is all ok), roundcube tell me:

    Impossibile connettersi al server IMAP

    Thisi is my /etc/roundcube/plugins/password/config.inc.php:

    what can i check?

    Reply
  • 2020-10-04 at 15:56
    Permalink

    Hi Cristoph,
    I try to test roundcube, but when I insert username and password (in mutt is all ok), roundcube tell me:

    Impossibile connettersi al server IMAP

    This is my /etc/roundcube/plugins/password/config.inc.php:
    I omit start and stop tag of php.

    // Empty configuration for password
    // See /usr/share/roundcube/plugins/password/config.inc.php.dist for instructions
    // Check the access right of the file if you put sensitive information in it.
    ###$config=array();
    $config[‘password_driver’] = ‘sql’;
    $config[‘password_minimum_length’] = 12;
    $config[‘password_force_save’] = true;
    $config[‘password_algorithm’] = ‘dovecot’;
    $config[‘password_dovecotpw’] = ‘/usr/bin/doveadm pw -s BLF-CRYPT’;
    $config[‘password_dovecotpw_method’] = ‘BLF-CRYPT’;
    $config[‘password_dovecotpw_with_method’] = true;
    $config[‘password_db_dsn’] = ‘mysql://mailadmin:installationpassword@localhost/mailserver’;
    $config[‘password_query’] = “UPDATE virtual_users SET password=%D WHERE email=%u”;

    what can i check?

    Reply
    • 2020-10-05 at 14:13
      Permalink

      What did you set the $config[‘default_host’] to?

      Reply
  • 2020-10-05 at 16:36
    Permalink

    Thanks Christoph, I found the error. I had done a copy and paste without replacing the domain. I had never used roundcube.

    Reply
  • 2020-10-05 at 17:07
    Permalink

    Now when I enter the username and password, it waits for a long time and does nothing

    Reply
  • 2020-10-05 at 17:49
    Permalink

    It rest in “loading…” for a long time and then does nothing more.
    which log can i watch?
    If I do tail -f /var/log/syslog, seems that roundcube does not query dovecot. while with mutt I see it interacting with dovecot.
    What can i check now?

    Reply
  • 2020-10-13 at 08:11
    Permalink

    Hi thanks for the workaround!
    in dovecote configuration (/etc/dovecot/conf.f/10-auth.conf) I have below configuration>>

    disable_plaintext_auth = yes
    auth_mechanisms = plain login
    !include auth-passwdfile.conf.ext

    In /etc/dovecot/conf.d/auth-passwdfile.conf.ext file I have below configuration:
    passdb {
    driver = passwd-file
    args = scheme=PLAIN username_format=%u /etc/dovecot/dovecot-users
    }

    userdb {
    driver = static
    args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n

    And I have listed my virtual users at dovecot-users file in below format:

    user@domain:password

    User login/logout mail send/receive is working fine.

    But I can not figure out the password changing mechanism. It will be appreciated if you look into my issue to help me. Thanks in advance.

    Reply

Leave a Reply to paride Cancel reply

Your email address will not be published. Required fields are marked *