Webmail

Webmail is gone in Mountain Lion. Not all users are pleased so it is time to install RoundCube mail to give them their beloved webmail back. RoundCube was used with Lion as the webmail solution and can be download from here.

But just installing it is not enough, it has to be installed as a full featured webapp in order to integrate nice with Mountain Lion. The standard security settings of the onboard PostgresQL database are pretty tight. They can be loosened, but to avoid potential update problems we’ll install MySQL as a second database server. Note that installing RoundCube mail requires some experience of working at the commandline.

Update: I just received notice that the folks at topicdesk.com have automated the process of restoring webmail functionality. If you don’t want to perform the steps written below you can use their installer. More info to be found here.

File locations

One of the first noticable differences between Lion and Mountain Lion is that the locations of configuration files have changed. Instead of configuring the webserver from /etc/apache2 as with Lion does Mountain Lion use /Library/Server/Web/Config/apache2/ as the configuration directory. In this directory is a subdirectory webapps that contains all the web-based applications such as calendar, wiki etc. The file com.example.mywebapp.plist will be used as a template to create the startup config plist file.

The php code from RoundCube mail will be installed outside of the standard OS X installation to ensure that the risk of loosing it with the next upgrade is minimal.

For this purpose it will be installed in /opt/webapps/webmail

Creating the filesystem structure and downloading RoundCube mail

Open a terminal as an administrator and  issue the following command:

Change to this directory:

With Safari download the RoundCube tar file from the download section on http://roundcube.net/ as the same administrator user that you are on the command line. The downloaded file wil be installed in the Downloads folder of this user.

Extract the downloaded tar file. Replace <username> with the shortname of the admin user that download RoundCube

Move the contents of the extracted file to the right location:

And check that everything is there:

Next visit the MySQL website and download the MySQL installer. The URL is http://www.mysql.com/downloads/mysql/, a direct download link is ftp://ftp.easynet.be/mysql//Downloads/MySQL-5.5/mysql-5.5.27-osx10.6-x86_64.dmg

Select the Mac OS X version, download it and install it as any other package. Note that the version indicates that it is for 10.6 (Snow Leopard), but it works fine with Mountain Lion (10.8)

The MySQL files are installed in /usr/local/mysql-5.5.27-osx10.6-x86_64. This path could be different if you download a newer version of MySQL. Don’t forget to start the MySQL server through System Preferences.

With all the files in place it is time to create the database

Create and configure the database

First go to the MySQL binary directory and then create a database user that will access the database:

Next create the database:

or, if your database is password protected:

Assign a user and  password to the database and import the SQL statements to create the database

Replace ‘the_new_password’ with the password that you want to assign.

Descend into the config directory and copy the template database config file to the file that will be used:

Edit the file db.inc.php with your favorite editor and look for the line that starts with $rcmail_config. Don’t forget to use sudo before the name of your editor otherwise you can’t save the changes.

Change this line:

into this one, replacing the_new_password with the password created above:

Important: The ip address should be used, not the word ‘localhost’!

Complete website configuration

First of all give RoundCube mail a default configuration. This file can be changed later to customize and debug your installation.

Still in the confg directory type

Find the line that starts with $rcmail_config[‘default_host’] and alter it so it looks like this:

Also alter the authentication type for imap by altering the following line from this:

into this:

Create the webapp to start RoundCube

The webapp needs an Apache config file and a plist file to work properly. In the plist file there will be a check to see if the Apache config file exists. If it does not exist it will not show up as a webapp in Server.app

First create the Apache config file.

and edit this file to contain the following content:

Change to the webapps directory:

Create a webapp plist file:

and edit this file, once again don’t forget sudo in front of the name of your editor. Make sure it looks like this:

With the webapp in place it is time to fire up Server.app and start the webapp:

Just follow the screenshots

Enable PHP if it is (still) disabled. Next click on Server Website to select it and then click on the pencil:

Select the ‘Edit Advanced Settings…’

Make sure the checkbox is activated for the newly added webapp, click OK, click done and give it a try

Log in with your username and password…

Disclaimer: All information posted is written with the upmost care and valid at the time of writing. Changes in versions can supersede the provided information. Please use your own judgement.

50 thoughts on “OS X Mountain Lion Webmail

  1. I’ve tried to follow your steps in doing this however I’ve reached an issue at the webapp part. No matter what I’ve tried I cannot get the webapp to show up in server.app “advanced settings”

    I’ve noticed a few things:

    1. This file does not exist but is mentioned in the plist
    /opt/webapps/webmail/httpd_webmail.conf

    2. We create a plist file called: nl.marcoach.webapps.webmail.plist

    but in the plist name key the name is without ‘webapps’

    Any clarification on this would be greatly appreciated.

  2. Thank you for the helpful tutorial.
    But I’ve the same problem. Please tell us, how we get the web app to show up in server.app and what about the ‘httpd_webmail.conf’.
    Thanks a lot.

    1. Webapp ist set up in the server app, known as as webapp “Roundcube webmail” but
      doesn’t show up in the web app here.

      It is reachable by something like “http://domain/webmail”

      i think, i like to have roundcube available via mail.domain.tld, which is better to configure than that s**** webapps.

  3. Hi. Do you configure LDAP for your Contacts, or do you use only internal Database? If you use LDAP, can you please post the Setttings?

    Thanks a lot :).

  4. When I get to the line: “./mysql -p roundcube < /opt/webapps/webmail/SQL/mysql.initial.sql" I receive: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES) Any idea what I need to do?

    1. It looks like you didn’t secure the MySQL root user with a password.
      Try the same command without -p and if it succeeds then you have to secure the MySQL root user to avoid anyone gaining unauthorized access to your database.

  5. I installed SQL server from the package… but it won’t start.

    I suspect I need a user, or configure the daemon to use a spcofoc user… but the instruction don’t go into how to ensure that MySQL starts in this vanilla example.

    Thanks in advance!

  6. I have followed these instructions to the T, but when I try and log into the webmail I get the following error:

    DATABASE ERROR: CONNECTION FAILED!
    Unable to connect to the database!
    Please contact you server-administrator.

    You have any ideas on what this could mean? I’d really appreciated any feedback, thanks

  7. F I X

    Alas, I can now log into my webmail server! This is a great guide by the way. I overlooked an aspect and boy did I pay the price. But once I made the following change all worked as expected.

    While editing the db.inc.php file and changing the $rcmail_config[‘db_dsnw’] line to account for the 127.0.0.1 ip address ALSO pay close attention to the following /roundcube’ part of the line as indicated in this guide. When I was editing my file it actually read /roundcubemail so I HAD TO CHANGE IT TO the /roundcube’ just as it is indicated in this guide. My assumption was that the default name was alright, but that’s where I went wrong. Hopefully this information can be helpful for others!

  8. got the next problem by creating de roundcube datebase. i got the next error

    CREATE DATABASE failed; error: ‘Access denied for user ”@’localhost’ to database ’roundcube”

    what can i do?

  9. HI. I’m try to follow the instructions, but on the step ./mysqladmin create roundcube I received an error msg – ./mysqladmin: CREATE DATABASE failed; error: ‘Access denied for user ”@’localhost’ to database ’roundcube”.
    And all has stopped. Can you please help to fix this??
    Mac OS X Server 10.8.2

  10. Thank you, John, had exactly the same problem. Then had 2 more brain dead problems – forgot to switch on mail in server and mysql in preferences. After that, worked like magic! 🙂 I was hesitant to “upgrade” my real server to 10.8 but after getting this running successfully on a test platform, I am stoked. Again, my thanks to all!

    ps, userdol, I got past this by adding -u root to the command line after setting up a mysql root user. see http://akrabat.com/computing/setting-up-php-mysql-on-os-x-10-8-mountain-lion/ and omit the {} when you type in your password

  11. Any idea why I’m getting a 404 on the /webmail URL? Server.app sees the web app, which is checked. Where does the alias for /webmail get created that directs it to the web app?

  12. As a followup-

    When I do a serveradmin settings web, it gives me this:

    web:definedWebApps:_array_index:17:name = “com.organization.webmail”
    web:definedWebApps:_array_index:17:displayName = “RoundCube webmail”
    web:definedWebApps:_array_index:18:requiredWebAppNames = _empty_array
    web:definedWebApps:_array_index:18:includeFiles = _empty_array
    web:definedWebApps:_array_index:18:requiredModuleNames = _empty_array
    web:definedWebApps:_array_index:18:startCommand = “”
    web:definedWebApps:_array_index:18:sslPolicy = 0
    web:definedWebApps:_array_index:18:requiresSSL = no
    web:definedWebApps:_array_index:18:requiredByWebAppNames = _empty_array

    Note the empty array for includeFiles. Nothing that I do allows it to populate with the proper file path.

    1. Of course, I now realize I was looking at two arrays, and that the proper line in item 17 is fine. But the includeFile still isn’t creating the proper alias.

  13. Figured it out. Apparently I had another alias that didn’t migrate from 10.6 properly.

  14. Beste Marco,

    Ik heb volgens de aanwijzingen alle stappen uitgevoerd om onder mountain lion de webmail functie toe te voegen. Na dit alles wil echter mijn server app de webservice en de certificate service niet meer opstarten. Apache en MySQL draaien wel gewoon, maar ik kom dus niet meer bij de instellingen van de webservice via Server app. Alvast hartelijk dank voor je hulp!

    Groet,

    Jan Henk

    1. Whenever you encounter a situation that you can’t get into the Web management part of Server.app you’ve probably got an error in the webapp plist file in /Library/Server/Web/Config/apache2/webapps/
      Please check it carefully, its easy to overlook something.
      Also make sure that the file httpd_webmail.conf is at least readable for the system user _www

  15. Hello, I would like you to ask how to change MySQL for Postgre as it is used in 10.8 by default or if there is any reason for using MySQL instead. Thank you

  16. Hi your tutorial was very helpful.
    There was only one problem the link:
    ./mysql -p roundcube < /opt/webapps/webmail/SQL/mysql.initial.sql should be
    ./mysql -u roundcube -p roundcube < /opt/webapps/webmail/SQL/mysql.initial.sql otherwise you are trying to run this as the system user. other than that great tutorial. I would also recommend people use pico instead of vi easier to work with.
    Now just left to figure out vacation notification…

    Thnaks

  17. I keep getting this:
    tar: Error opening archive: Failed to open ‘/Users/serveradmin/Downloads/roundcubemail-0.8.0.tar’
    Every single time I enter sudo tar xvf /Users//Downloads/roundcubemail-0.8.0.tar

    1. Does the file exist? And is it decompressed already?
      You might want to change the command to tar xvzf /Users/serveradmin/Downloads/roundcubemail-0.8.0.tar.gz

      1. Turns out it was a different version so it was 0.8.6. Now when I try to move the extracted file (sudo mv roundcubemail-0.8.0/* .) it says mv: rename roundcubemail-0.8.0/* to ./*: No such file or directory
        Thanks for getting back to me for my first question!

  18. Worked well on ML 10.8.3 except i had to change CRAM-MD5 to PLAIN (it’s SSL so i don’t care) to be able to authenticate.

    Thank you Marco for this helpful wiki.

    1. Many, many years ago it was a revolution to have upper- and lowercase characters on a keyboard. People were proud to be able to differentiate between these and since them the Unix OS does this as well.

      OS X is Unix based and therefor the Apache web server considers lowercase to be different from uppercase, a mechanism known as Case Sensitive. On the filesystem level OS X has switched to the Windows behavior were there is no distinction between the two. This mechanism is called Case Preserving.

      1. So I assume there is no changing this or adding this as a feature, its not a big deal and it is interesting to know that is the reason why because like most people I am used to windows not caring whether it is in caps or not.

        Thanks for your help, and this was a great writeup, I had no issues setting it up, and now that I’ve jacked up my server from trying to mess with one to many things I’ll be using it again soon!

        1. You’re welcome. And if you really want you can try to add or activate an Apache module that will take care of capitalization to a certain extent. I think it is called mod_speling, but I’m not sure. I’ve never had the need to dive into this.

          Another way of doing it is by adding multiple Alias lines with all different ways of spelling webmail in the file https_webmail.conf.
          Three Aliases have been configured to deal with the most common spellings used:
          Alias /webmail “/opt/webapps/webmail/”
          Alias /Webmail “/opt/webapps/webmail/”
          Alias /WebMail “/opt/webapps/webmail/”

          But you could add more, e.g.:
          Alias /WEBMAIL “/opt/webapps/webmail/”
          Alias /WeBmAiL “/opt/webapps/webmail/”

  19. Hi, thanks for this article.. However (!) I’m stuck and don’t seem to be able to see where I’ve gone wrong, even after following all the other posts, it looks correct to me.

    I have wiki pages installed also, so before clicking Roundcube webmail in Advanced Settings it works, enable this and Wiki stops working and I’m not able to see webmail either (404 error)
    So below is all my settings hopefully somebody will spot what is missing! Thanks

    System: Mac mini Server 2013 – Mountain Lion Server
    Downloaded Roundcube 0-1.9.0.tar extracted all ok
    Downloaded MySQL 5.6.11 osx10.7-x86_64.tar extracted and installed all OK

    Created Roundcube database, GRANTing access was a mine field however this was successful in the end
    +——————————————————————————————————————+
    | Grants for roundcube@localhost |
    +——————————————————————————————————————+
    | GRANT USAGE ON *.* TO ’roundcube’@’localhost’ IDENTIFIED BY PASSWORD ‘*3C54C2DDBF76518BEB4AA9B9C9FAAE461CB0581F’ |
    | GRANT ALL PRIVILEGES ON roundcube.* TO ’roundcube’@’localhost’ |
    +——————————————————————————————————————+
    2 rows in set (0.00 sec)

    Copied and edited db.inc.php – changed the following line
    $rcmail_config[‘db_dsnw’] = ‘mysql://roundcube:@127.0.0.1/roundcube’;

    Copied and changed main.inc.php – changed the following line
    $rcmail_config[‘default_host’] = ‘tls://127.0.0.1/’;
    $rcmail_config[‘imap_auth_type’] = CRAM_MD5;

    Created httpd_webmail.conf
    Alias /webmail “/opt/webapps/webmail/”
    Alias /Webmail “/opt/webapps/webmail/”
    Alias /WebMail “/opt/webapps/webmail/”
    Requestheader set x-apple-service-webmail-enabled true

    Options -Indexes FollowSymLinks

    Created nl.marcoach.webapps.webmail.plist

    name
    nl.marcoach.webmail
    displayName RoundCube webmail
    proxies

    includeFiles
    /opt/webapps/webmail/httpd_webmail.conf
    installationIndicatorFilePath
    /opt/webapps/webmail/httpd_webmail.conf

    Roundcube webmail is listed successfully in Advanced settings but with not load in safari!
    Can anybody see what I’ve done wrong???

    1. It seems that same characters are lost in your comment but I assume you’ve got the files correct on your system.
      There could several reasons why webmail wouldn’t load even though you have activated it in advanced settings.
      Wrong capitalization could be one, make sure you type everything in lower case. Another reason could be that PHP is not enabled at the main pane of the Websites configuration of Server.app. Or not beinig able to connect to the mysql database.
      I would suggest checking the Apache log files (/var/log/apache2/access_log and /var/log/apache2/error_log) to see if they would reveal a reason why roundcube is not loading.

      When looking at a snippet of code you posted this line got my attention:
      $rcmail_config['db_dsnw'] = ‘mysql://roundcube:@127.0.0.1/roundcube’;
      There is no password on this line for the mysql user roundcube which turns it into an empty password since you do have a colon before the ampersand. Hopefully you have assigned a password to this user, please enter it here.

      Based on the information above the line should read:
      $rcmail_config['db_dsnw'] = ‘mysql://roundcube:*3C54C2DDBF76518BEB4AA9B9C9FAAE461CB0581F’@127.0.0.1/roundcube’;

      This could still go wrong because you’ve used a special character to generate a complex password.
      Complex passwords are good of course, but special characters can always be a source of problems when used in scripts. They might need escaping to loose their special meaning.

      Why don’t you try it with a less complex password first? Just to see if that is causing the problem and then work your way up?

  20. Hi thanks for the reply… to clarify I removed my password from the snippet and enclosed brackets instead but they didn’t appear when posted(!!), however not sure way SHOW GRANTS displays this long complex password… Could this be the problem, I did have a few problems getting access to change the privilages?

    I had noted other comments on the webmail not WEBMAIL part, wiki (not WIKI) has the same problem – PHP has been enabled.

    I’ll check the Apache log’s later, like you said it may reveal more. Also on reflection, I couldn’t do the following:

    Don’t forget to start the MySQL server through System Preferences.

    My System Preferences doesn’t show MySQL, I had to start it from Terminal..? I’ll look into this more also

    Thanks for your help

  21. Looking at the apache2 error log I get the following

    [Wed May 15 08:59:49 2013] [error] [client 192.168.31.50] File does not exist: /Library/Server/Web/Data/Sites/Default/webmail

    Any thoughts?

  22. So I decided to do the following

    sudo cp -r /opt/webapps/ /library/Server/Web/Data/Sites/Default

    And the webpage /webmail now works!!! Thanks for the guide… Next is to try and create a web calendar for everybody to use

    1. That’s a way around it… It still hasn’t fixed the issue with the Alias…

      Another reason why Aliases are not recognized is if you enable the webapp for a particular domain and try to connect using another domain name or ip address. In that case you’re send back to the default website.

    2. I’m not using the web calendar a lot. Turning on the Wiki gives access to the calendar and you might be able to achieve what you want from the Wiki system. It has builtin calendaring…

Comments are closed.