correct html replacing
parent
0e632d00f7
commit
2780ade490
|
@ -0,0 +1,7 @@
|
|||
git add *
|
||||
|
||||
read -p "Commit message: " commit_message
|
||||
|
||||
git commit -m "$commit_message"
|
||||
|
||||
git push -u origin main
|
|
@ -56,7 +56,6 @@ func (m *Mail) Send(htmlBody, textBody string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
gocnjhelper.LogDebugf("SEND MAIL %s", msg)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -120,6 +119,7 @@ func (m *Mail) RenderTemplate() (htmlBody, textBody string, err error) {
|
|||
}
|
||||
|
||||
body.HTML = []byte(strings.Replace(string(body.HTML), "%"+key+"%", v, -1))
|
||||
body.PlainText = []byte(strings.Replace(string(body.PlainText), "%"+key+"%", v, -1))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,15 +136,26 @@ func (m *Mail) RenderTemplate() (htmlBody, textBody string, err error) {
|
|||
htmlBuf := new(bytes.Buffer)
|
||||
textBuf := new(bytes.Buffer)
|
||||
|
||||
gocnjhelper.LogDebugf("BODY DATA %s ", m.BodyData)
|
||||
|
||||
if err := htmlTemplate.Execute(htmlBuf, m.BodyData); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// the execute function replaces all < and > with < and > in html body
|
||||
// so we have to replace them back
|
||||
// replace all < and > with < and > in html body
|
||||
|
||||
htmlBody = strings.ReplaceAll(htmlBuf.String(), "<", "<")
|
||||
htmlBody = strings.ReplaceAll(htmlBody, ">", ">")
|
||||
|
||||
// Execute text template
|
||||
|
||||
if err := textTemplate.Execute(textBuf, m.BodyData); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return htmlBuf.String(), textBuf.String(), nil
|
||||
return htmlBody, textBuf.String(), nil
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue