Nextcloud Mail Developer Documentation

Resetting the app

Connect to your database and run the following commands (oc_ is the default table prefix):

DELETE FROM oc_appconfig WHERE appid = 'mail';
DELETE FROM oc_migrations WHERE app = 'mail';
DROP TABLE oc_mail_accounts;
DROP TABLE oc_mail_aliases;
DROP TABLE oc_mail_coll_addresses;
DROP TABLE oc_mail_attachments;
DROP TABLE oc_mail_mailboxes;
DROP TABLE oc_mail_messages;
DROP TABLE oc_mail_recipients;
DROP TABLE oc_mail_classifiers;
DROP TABLE oc_mail_trusted_senders;
DROP TABLE oc_mail_tags;
DROP TABLE oc_mail_message_tags;
DROP TABLE oc_mail_provisionings;

Enable CKEditor Inspector

ckeditor inspector


Testing LDAP aliases provisioning

Testing the ldap aliases provisioning requires:

  1. LDAP service configured in Nextcloud
  2. IMAP service using LDAP for authentication
  3. A provisioning configuration for Mail

LDAP service configured in Nextcloud

The fastest way to setup Nextcloud with LDAP is

It's still possible to integrate a ldap service into your own development setup with docker-compose.

  image: osixia/openldap:1.5.0
  command: --copy-service --loglevel debug
    - 50003:389
    - ./ldap:/container/service/slapd/assets/config/bootstrap/ldif/custom
    LDAP_BASE_DN: dc=planetexpress,dc=com

  image: osixia/phpldapadmin:0.9.0
    - 50004:443

To have sample users we are using - Download the directory and save it in the same directory as docker-compose.yml. - Delete 99_others.ldif (otherwise you have a lot of additional test users). - Adjust the port mapping for your use case if necessary.

Run docker-compose to start ldap and ldapadmin. Visit ldapadmin at http://localhost:50004 (or whatever port you configured) and try to login with

ldapadmin overview

Next step is to configure our LDAP service in Nextcloud. - Login as administrator - Go to apps and enable "LDAP user and group backend" - Go to settings -> LDAP/AD integration

ldap in nextcloud - server

Click Test Base DN to test the configuration.

ldap in nextcloud - user

Click Verfiy settings and count users.

ldap in nextcloud - login attributes

ldap in nextcloud - groups

ldap in nextcloud - groups

IMAP service using LDAP for authentication

In a production environment we would configure our IMAP service to authenticate against the LDAP service. For our testing scenario it's sufficient to configure some LDAP accounts on the IMAP service.

  image: christophwurst/imap-devel:latest
    - "25:25"
    - "143:143"
    - "993:993"
    - "4190:4190"
    - MAILNAME=mail.domain.tld
    - MAIL_ACCOUNTS=admin@test.local,password,bender,amy

Extend our docker-compose.yml and add the imap test image. Use the MAIL_ACCOUNTS environment variable to create test accounts for IMAP.

ldap in nextcloud - user management is the username for the user in the LDAP directory. The username might be different on your setup. Please lookup the right values in the Nextcloud user management.

To create a IMAP account for Amy and Bender add to MAIL_ACCOUNTS.,amy,bender

The password is (for our sample data) the display name in lowercase. Note that accounts are seperated by a space.

A provisioning configuration for Mail

ldap in nextcloud - provisioning configuration

The above configuration will query the mailAlias attribute for each user and use it to create and delete aliases.

Our sample data for LDAP does not contain mailAlias. To add one or more mailAliases to a user: - Visit ldapadmin - Expand dc=planetexpress,dc=com - Expand ou=people - Pick a user (e.g Bender) - Look for objectClass -> Click add value -> Select PostfixBookMailAccount -> Click Add new ObjectClass - Click Add new attribute -> Select mailAlias -> Enter -> Press Enter -> Click Update Object

Now login to Nextcloud as Bender and go to Mail. See as Alias in the Account settings for the provisoned mail account.