Roundcube

Roundcube is a browser-based open-source webmail client that provides a full-featured email interface with support for IMAP, SMTP, address books, and extensible plugins.

Code

The NixOS module for Roundcube integrates almost immediately with NixOS mailserver, automatically configuring an Nginx virtual host and ACME-managed TLS for secure webmail access; using other web servers may require additional manual setup.

Once set up you can login with your login account credentials.

{
  config,
  pkgs,
  ...
}:

{
  services.roundcube = {
    enable = true;
    hostName = "webmail.example.com"; # the nginx vhost
    package = pkgs.roundcube.withPlugins (
      plugins: with plugins; [
        # external plugins to be included
        # https://search.nixos.org/packages?query=roundcubePlugins
        persistent_login
      ]
    );
    # activate plugins
    plugins = [
      "persistent_login"
      "managesieve" # built-in
    ];
    dicts = with pkgs.aspellDicts; [
      # https://search.nixos.org/packages?query=aspellDicts
      en
    ];
    maxAttachmentSize = config.mailserver.messageSizeLimit / 1024 / 1024;
    extraConfig = ''
      $config['imap_host'] = "ssl://${config.mailserver.fqdn}";
      $config['smtp_host'] = "ssl://${config.mailserver.fqdn}";
      $config['smtp_user'] = "%u";
      $config['smtp_pass'] = "%p";

      $config['managesieve_host'] = "tls://${config.mailserver.fqdn}";
      $config['managesieve_port'] = 4190;
      $config['managesieve_usetls'] = true;
    '';
  };

  services.nginx.virtualHosts.${config.services.roundcube.hostName} = {
    enableACME = true;
    forceSSL = true;
  };

  networking.firewall.allowedTCPPorts = [
    80
    443
  ];
}

To use a different reverse proxy, such as Caddy, bind Roundcube's Nginx virtual host to 127.0.0.1 on a custom port and disable SSL and ACME, as the reverse proxy will handle those.

{ config, ... }:
{
  services.nginx.virtualHosts.${config.services.roundcube.hostName} = {
    forceSSL = false;
    enableACME = false;
    listen = [
      {
        addr = "127.0.0.1";
        port = 8000;
      }
    ];
  };

  services.caddy.virtualHosts."${config.services.roundcube.hostName}".extraConfig = ''
    reverse_proxy localhost:8000
  '';
}