Configuring and provisioning IMAP for all accounts does not work

Is it somehow possible to configure and provision IMAP for all accounts using OCC?

I am trying to automate the installation, and want to configure the SMTP, IMAP and Sieve hosts and their information automatically using OCC and then provision them to all users using a specific template, just like what the web UI can do.

Is this some how possible?

I came a bit further probably after following this documentation and this GitHub PR, but It is still not working, but I guess I am on the right way, I added this config file to my deployment, but still I see no changes in the app itself:

mail.config.php: |-
  <?php
  $CONFIG = array (
    'app.mail.accounts.default' => [
        'email' => '%USERID%@DOMAIN.com',
        'imapHost' => 'mail.DOMAIN.com',
        'imapPort' => 993,
        'imapUser' => '%USERID%',
        'imapSslMode' => 'ssl',
        'smtpHost' => 'mail.DOMAIN.com',
        'smtpPort' => 465,
        'smtpUser' => '%USERID%',
        'smtpSslMode' => 'ssl',
    ],
  );

Checking the config shows that it is there:

root@nextcloud-765f454fd5-mgqhm:/var/www/html# sudo -u www-data PHP_MEMORY_LIMIT=512M /var/www/html/occ config:list
{
    "system": {
        "htaccess.RewriteBase": "\/",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "apps_paths": [
            ...
        ],
        "app.mail.accounts.default": {
            "email": "%USERID%@DOMAIN.com",
            "imapHost": "mail.DOMAIN.com",
            "imapPort": 993,
            "imapUser": "%USERID%",
            "imapSslMode": "ssl",
            "smtpHost": "mail.DOMAIN.com",
            "smtpPort": 465,
            "smtpUser": "%USERID%",
            "smtpSslMode": "ssl"
        },

The mail is still unconfigured and I see no config in the adminsitration β†’ groupware. Am I supposed to do anything else? What could be wrong?

I do not know, whether it is a faulty entry while anonymizing:
In the screenshot there is %user123%domain.dom.
Shouldn’t it be %user123%@domain.com?

Thank you for you reply, @Mornsgrans

It was just for testing, but I replaced it with valid values, still not working.

Is it correct that this config is part of the system? Or should it be somewhere else?

@mnoureldin I am also trying to automate the mail installation, including mail provisioning. I also tried your approach with the config.php, but it did not work for me (is this probably not supported anymore in NC 27.1.3?)
However, what worked for me is an insert into the nextcloud database, in my case with environment variables:

mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -D${MYSQL_DATABASE} -e β€œinsert into oc_mail_provisionings(id,provisioning_domain,email_template,imap_user,imap_host,imap_port,imap_ssl_mode,smtp_user,smtp_host,smtp_port,smtp_ssl_mode,ldap_aliases_provisioning,ldap_aliases_attribute) values (1,β€˜${MAIL_DOMAIN}’,β€˜%EMAIL%’,β€˜%EMAIL%’,β€˜${MAIL_IMAP_HOST}’,β€˜${MAIL_IMAP_PORT}’,β€˜${MAIL_IMAP_SSL_MODE}’,β€˜%EMAIL%’,β€˜${MAIL_SMTP_HOST}’,β€˜${MAIL_SMTP_PORT}’,β€˜${MAIL_SMTP_SSL_MODE}’,β€˜${MAIL_LDAP_ALIASES_PROVISIONING}’,β€˜${MAIL_LDAP_ALIASES_ATTRIBUTE}’);”

Hope that helps, although it is not with occ, but a method to automatize the mail provisioning configuration.

1 Like

Thank you for you reply. This does not seem to be safe to manipulate the database manually. If there is any side-effect that should be done, it will be missed.

UPDATE

Actually manipulating the DB seems the only possible way to do this, according to this official statement.

Configuring the mail for all accounts using the config.php is not working Β· Issue #8964 Β· nextcloud/mail (github.com)

@gehrigmobi may I ask you if you are still using this SQL command and tested it properly and everything is still working properly?

Here is a rewrite to make more human-readable:

mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -D${MYSQL_DATABASE} -e "
    INSERT INTO oc_mail_provisionings(
        id,
        provisioning_domain,
        email_template,
        imap_user,
        imap_host,
        imap_port,
        imap_ssl_mode,
        smtp_user,
        smtp_host,
        smtp_port,
        smtp_ssl_mode,
        ldap_aliases_provisioning,
        ldap_aliases_attribute
    ) 
    VALUES (
        1,
        '${MAIL_DOMAIN}',
        '%EMAIL%',
        '%EMAIL%',
        '${MAIL_IMAP_HOST}',
        '${MAIL_IMAP_PORT}',
        '${MAIL_IMAP_SSL_MODE}',
        '%EMAIL%',
        '${MAIL_SMTP_HOST}',
        '${MAIL_SMTP_PORT}',
        '${MAIL_SMTP_SSL_MODE}',
        '${MAIL_LDAP_ALIASES_PROVISIONING}',
        '${MAIL_LDAP_ALIASES_ATTRIBUTE}'
    );
"

I’m using it now since last autumn to play around with different Nextcloud configurations. I’ve always used the nextcloud:latest Docker image and did the initial settings in /docker-entrypoint-hooks.d/post-installation/, e.g. installing apps, ldap, theming (with OCC), but also the above SQL command.
So far it worked fine, all users always had functioning mail boxes.

1 Like

Thanks for confirming this. I will give it a try!