nextcloud / nextcloud/server

[Bug]: Custom email templates don't work in custom app.

Open
#45,392 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 28-feedback bug feature: emails pending documentation
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
Bug description

According to the docs, we can override the email template by extending the Class OC\Mail\EMailTemplate
https://docs.nextcloud.com/server/29/admin_manual/configuration_server/email_configuration.html#using-email-templates (Edited link to current version)

config/additional.config.php:

<?php
$CONFIG = array (
    'mail_template_class' => 'OCA\MyApp\Mail\EMailTemplateModified',
);

This does not work if the extending class is put into the namespace of my custom app (as suggested in the doc).

Maybe there is some problem with loading the OCA\\MyApp namespace, I'm not sure. There were no error messages in the logs.

If I create the class in the same namespace, it works fine:

config/additional.config.php:

<?php
$CONFIG = array (
    'mail_template_class' => 'OC\Mail\EMailTemplateModified',
);

lib/private/Mail/EMailTemplateModified.php

<?php

namespace OC\Mail;

use OC\Mail\EMailTemplate;

class EMailTemplateModified extends EMailTemplate
{
    public function addHeader(): void
    {
        if ($this->headerAdded) {
            return;
        }
        $this->headerAdded = true;

        $logoUrl = 'https://nextcloud.mydomain.com/custom_apps/myapp/img/logo.png';
        $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getDefaultColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
    }
}

See this thread in the forums: https://help.nextcloud.com/t/change-style-for-emails/165481/8?u=matengor

Steps to reproduce
  1. Create extending class in custom app (e.g. custom_apps/my_app/lib/Mail/EMailTemplateModified.php
  2. Set this as 'mail_template_class' in config.php
  3. Send test mail (e.g. Users > Resend welcome mail)

Result:

  1. No modifications in received mail
  2. No log entries about a missing PHP class
Expected behavior

The received mail should contain my modifications

Installation method

Official All-in-One appliance

Nextcloud Server version

28

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.2

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report
{
    "system": {
        "force_language": "en",
        "one-click-instance": true,
        "one-click-instance.user-limit": 100,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "appsallowlist": false,
        "check_data_directory_permissions": false,
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "password": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        },
        "overwritehost": "nextcloud.mydomain.com",
        "overwriteprotocol": "https",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "localhost",
            "nextcloud.mydomain.com"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "pgsql",
        "version": "28.0.5.1",
        "overwrite.cli.url": "https:\/\/nextcloud.mydomain.com\/",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "maintenance": false,
        "updatedirectory": "\/nc-updater",
        "loglevel": "2",
        "app_install_overwrite": [
            "nextcloud-aio",
            "mailnotifier",
            "myapp"
        ],
        "log_type": "file",
        "logfile": "\/var\/www\/html\/data\/nextcloud.log",
        "log_rotate_size": "10485760",
        "log.condition": {
            "apps": [
                "admin_audit"
            ]
        },
        "preview_max_x": "2048",
        "preview_max_y": "2048",
        "jpeg_quality": "60",
        "enabledPreviewProviders": {
            "1": "OC\\Preview\\Image",
            "2": "OC\\Preview\\MarkDown",
            "3": "OC\\Preview\\MP3",
            "4": "OC\\Preview\\TXT",
            "5": "OC\\Preview\\OpenDocument",
            "6": "OC\\Preview\\Movie",
            "7": "OC\\Preview\\Krita",
            "0": "OC\\Preview\\Imaginary"
        },
        "enable_previews": true,
        "upgrade.disable-web": true,
        "mail_smtpmode": "smtp",
        "trashbin_retention_obligation": "auto, 30",
        "versions_retention_obligation": "auto, 30",
        "activity_expire_days": "30",
        "simpleSignUpLink.shown": false,
        "share_folder": "\/Shared",
        "one-click-instance.link": "https:\/\/nextcloud.com\/all-in-one\/",
        "upgrade.cli-upgrade-link": "https:\/\/github.com\/nextcloud\/all-in-one\/discussions\/2726",
        "allow_local_remote_servers": true,
        "davstorage.request_timeout": 3600,
        "htaccess.RewriteBase": "\/",
        "dbpersistent": false,
        "files_external_allow_create_new_local": false,
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "preview_imaginary_url": "***REMOVED SENSITIVE VALUE***",
        "mail_sendmailmode": "smtp",
        "defaultapp": "",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "587",
        "mail_smtpauth": 1,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "maintenance_window_start": 100,
        "auth.bruteforce.protection.enabled": true,
        "ratelimit.protection.enabled": true,
        "preview_imaginary_key": "01905d44657ae39b27e597df8478fccfc36020bac48ddc0c"
    }
}
List of activated Apps
Enabled:
  - activity: 2.20.0
  - admin_audit: 1.18.0
  - calendar: 4.7.4
  - circles: 28.0.0
  - cloud_federation_api: 1.11.0
  - comments: 1.18.0
  - contacts: 5.5.3
  - contactsinteraction: 1.9.0
  - dashboard: 7.8.0
  - dav: 1.29.1
  - deck: 1.12.2
  - federatedfilesharing: 1.18.0
  - federation: 1.18.0
  - files: 2.0.0
  - files_automatedtagging: 1.18.0
  - files_pdfviewer: 2.9.0
  - files_reminders: 1.1.0
  - files_sharing: 1.20.0
  - files_trashbin: 1.18.0
  - files_versions: 1.21.0
  - firstrunwizard: 2.17.0
  - flow_notifications: 1.8.0
  - groupfolders: 16.0.6
  - logreader: 2.13.0
  - lookup_server_connector: 1.16.0
  - mailnotifier: 0.0.3
  - nextcloud-aio: 0.5.0
  - nextcloud_announcements: 1.17.0
  - notes: 4.10.0
  - notifications: 2.16.0
  - notify_push: 0.6.11
  - oauth2: 1.16.3
  - password_policy: 1.18.0
  - photos: 2.4.0
  - privacy: 1.12.0
  - provisioning_api: 1.18.0
  - recommendations: 2.0.0
  - related_resources: 1.3.0
  - richdocuments: 8.3.7
  - serverinfo: 1.18.0
  - settings: 1.10.1
  - sharebymail: 1.18.0
  - support: 1.11.1
  - survey_client: 1.16.0
  - tasks: 0.16.0
  - text: 3.9.1
  - theming: 2.3.0
  - theming_customcss: 1.16.0
  - twofactor_backupcodes: 1.17.0
  - twofactor_totp: 10.0.0-beta.2
  - user_status: 1.8.1
  - viewer: 2.2.0
  - weather_status: 1.8.0
  - workflow_script: 1.13.1
  - workflowengine: 2.10.0
Disabled:
  - bruteforcesettings: 2.8.0
  - encryption: 2.16.0
  - files_external: 1.20.0
  - files_rightclick: 0.15.1 (installed 1.6.0)
  - suspicious_login: 6.0.0
  - systemtags: 1.18.0 (installed 1.18.0)
  - user_ldap: 1.19.0
Nextcloud Signing status
No errors have been found.
Nextcloud Logs
-
Additional info

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the email-template documentation and the mail_template_class setting in config/additional.config.php. Compare the working lib/private/Mail/EMailTemplateModified.php example with the equivalent class under custom_apps/my_app/lib/Mail/EMailTemplateModified.php, then trace how the class is loaded when a welcome mail is sent. Done means the custom-app class is used and its mail modification appears without missing-class errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.