Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 of 8 tasks
localhorst opened this issue May 17, 2024 · 3 comments
Open
5 of 8 tasks

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

localhorst opened this issue May 17, 2024 · 3 comments
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 28-feedback bug feature: emails pending documentation This pull request needs an associated documentation update

Comments

@localhorst
Copy link

localhorst commented May 17, 2024

⚠️ 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

@localhorst localhorst added 0. Needs triage Pending check for reproducibility or if it fits our roadmap bug labels May 17, 2024
@kesselb
Copy link
Contributor

kesselb commented May 17, 2024

Thanks for your report 👍

I also had problems a while ago making a custom email template work in an app namespace. Adding lib/AppInfo/Application.php like in our app template helped.

Something appears to be broken for the apps loading when no application file is present or no custom autoloader (e.g. composer) is used.

@joshtrichards
Copy link
Member

joshtrichards commented May 17, 2024

Likely unrelated in this particular case, but make sure you're referencing current documentation. That link is for v17 (!).

Also, once we sort out what's going on here, let's update the template docs. :-)

@joshtrichards joshtrichards added feature: emails pending documentation This pull request needs an associated documentation update labels May 17, 2024
@localhorst
Copy link
Author

That link is for v17 (!).

Thanks. I updated the link to v29.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 28-feedback bug feature: emails pending documentation This pull request needs an associated documentation update
Projects
None yet
Development

No branches or pull requests

4 participants