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

Cannot change email subjects #27793

Open
sepsol opened this issue Oct 26, 2023 · 10 comments · May be fixed by #27861
Open

Cannot change email subjects #27793

sepsol opened this issue Oct 26, 2023 · 10 comments · May be fixed by #27861
Labels

Comments

@sepsol
Copy link

sepsol commented Oct 26, 2023

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
Copy link
Author

sepsol commented Oct 30, 2023

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
Copy link
Member

lng2020 commented Oct 31, 2023

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 (go-gomail/gomail#182) 🕯️ . 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
Copy link
Author

sepsol commented Oct 31, 2023

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
Copy link
Member

lng2020 commented Oct 31, 2023

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

@sepsol
Copy link
Author

sepsol commented Oct 31, 2023

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
Copy link
Member

lng2020 commented Oct 31, 2023

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
Copy link
Author

sepsol commented Oct 31, 2023

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
Copy link
Member

lng2020 commented Oct 31, 2023

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
Copy link
Member

lng2020 commented Oct 31, 2023

see description of #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
Copy link
Author

sepsol commented Oct 31, 2023

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?

@lng2020 lng2020 linked a pull request Nov 1, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants