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

Incorrect behavior using html/template with AddAlternativeWriter #176

Open
BorisKoz opened this issue Dec 27, 2022 · 3 comments
Open

Incorrect behavior using html/template with AddAlternativeWriter #176

BorisKoz opened this issue Dec 27, 2022 · 3 comments

Comments

@BorisKoz
Copy link

BorisKoz commented Dec 27, 2022

There is an issue where if the template crashes, the gomail.Send(sender, msg) returns the error, therefore implying correct error handling, but the email is sent regardless of template execution.
I.e.: the html contains:

a class="button-3" href="{{.Data.ConfirmationLink}}"> Confirm Email

where Data is a map. the template is configured for "missingkey=error", so if Data does not contain this key, the function tmp.execute(w, mail) will return an error. However, the email will still be sent:
Снимок экрана 2022-12-27 в 13 47 37
As seen, with the error log being:

{"level":"error","time":"2022-12-27T13:47:24+03:00","message":"Could not send email to "xxx": gomail: could not send email 1: template: emailConfirmation.html:110:53: executing "emailConfirmation.html" at <.Data.ConfirmationLink>: map has no entry for key "ConfirmationLink""}

I might be wrong in pointing this out, but in my opinion, if an error is found while executing the message template writer, the whole message should be discarded

@BorisKoz
Copy link
Author

I should add, that executing the template beforehand is an option, and it certainly helps, but it means wasting memory and performance - you need an extra buffer for the mail and an extra execution time

@wneessen
Copy link

This module isn't maintained anymore. It might be worth looking at go-mail which is actively maintained and supports text.Template/html.Template out of the box. The syntax is very similar, so a switch should be faily simple.

@BorisKoz
Copy link
Author

BorisKoz commented Dec 27, 2022

This module isn't maintained anymore. It might be worth looking at go-mail which is actively maintained and supports text.Template/html.Template out of the box. The syntax is very similar, so a switch should be faily simple.

Thank you! managed to switch in a blink of an eye. The only thing is - got some problems with SMTPAuthLogin there. maybe would open a request later, not a pressing issue - plain works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants