go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.95k stars 5.48k forks source link

Cannot change email subjects #27793

Open sepsol opened 1 year ago

sepsol commented 1 year ago

Description

I am trying to modify the subject lines of emails sent out from my self-hosted gitea instance (via docker-compose).

I am following this page in the docs: https://docs.gitea.com/administration/mail-templates. I have ran gitea embedded extract --destination /data/gitea templates/mail/** and modified one of the downloaded templates and added this line at the very top:

Test Subject
---
<!DOCTYPE html>
<body>
...
</body>

And then I ran docker compose restart to restart the gitea server. But my changes to the subject line are disregarded and .FallbackSubject from the metadata context is used. I have tested and I have no issue modifying the email body, it's just the email subject.

Any help would be highly appreciated, thanks!

Gitea Version

1.20.5

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.40.1

Operating System

Debian 12

How are you running Gitea?

I followed this guide to create gitea with postgres using docker-compose: https://docs.gitea.com/installation/install-with-docker#postgresql-database

Database

PostgreSQL

sepsol commented 1 year ago

I have posted my issue on all of the official channels and still have got not a single word in response. Could someone please let me know if this is acknowledged?

lng2020 commented 1 year ago

Have you contained <title>{{.Subject}}</title> in your HTML template for the email body? This will override the subject you defined. We use gomail to send mails but the project has been unmaintained for 7 years because the creator passed away according to (https://github.com/go-gomail/gomail/issues/182) :candle: . Maybe we should consider the alternative(though it sounds brutal) https://github.com/Shopify/gomail may be a choice or we can fork our own version.

sepsol commented 1 year ago

Wow, that is terribly sad :( 🕯️ I tried both removing the line starting with <title> and replacing it with <title>{{.Subject}}</title> and restarted the server but still had no luck with changing the subject, though changing the body still works fine. Honestly I don't have any experience in golang whatsoever but your choice seems solid

lng2020 commented 1 year ago

Can u show me the structure of your email template? Here is mine which works well.

That's a new subject
-------------------
<!DOCTYPE html>
<html>
<body>
....
</body>
</html>
![image](https://github.com/go-gitea/gitea/assets/70063547/104188ad-7984-446d-b453-aaddd1b516e4)
sepsol commented 1 year ago

Sure thing, here you go:

Test Subject
------------
<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="format-detection" content="telephone=no,date=no,address=no,email=no,url=no">
        <title>{{.Subject}}</title>
</head>

{{$set_pwd_url := printf "%[1]suser/forgot_password" AppUrl}}
<body>
        <p>{{.Subject}}</p>one two<br>
        <p>{{.locale.Tr "mail.hi_user_x" (.DisplayName|DotEscape) | Str2html}}</p><br>
        <p>{{.locale.Tr "mail.register_notify.text_1" AppName}}</p><br>
        <p>{{.locale.Tr "mail.register_notify.text_2" .Username}}</p><p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p><br>
        <p>{{.locale.Tr "mail.register_notify.text_3" ($set_pwd_url | Escape) | Str2html}}</p><br>

        <p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
</body>
</html>

Template is from: /data/gitea/templates/mail/auth/register_notify.tmpl

lng2020 commented 1 year ago

Have you contained <title>{{.Subject}}</title> in your HTML template for the email body? This will override the subject you defined.

What I mean is removing this <title>{{.Subject}}</title> or just removing the <head></head>. See my example above.

sepsol commented 1 year ago

That still doesn't work. But the one two text in the first line of body is printed fine. I'm testing that template from the screen below in the dashboard if it matters:

image

P.S. I've also took a look at the "Show Original" feature of gmail and the new subject line is not reflected there as well.

lng2020 commented 1 year ago

That's a bug. Seems like Gitea only applies this --- subject to issue related mail while others just use the default one. So our results are both reasonable now.

lng2020 commented 1 year ago

see description of https://github.com/go-gitea/gitea/pull/8329 which is the PR introduced the mail template function.

Future enhancements (for other PRs) [ ] Apply templates to all mail types (activate account, reset password, etc.). [ ] Support the use of {{.i18n.Tr}} for localization, currently tightly coupled to Macaron.

It seems no one doing the following PR in these four years...

sepsol commented 1 year ago

Got it, thanks for looking into this! I am looking into the PR's diff but it's really hard for me to wrap my head around both the code structure and the Go syntax. Do you think it is possible that you could look into this?