Refactoring

This commit is contained in:
Chris Mann 2023-07-26 10:48:07 +02:00
parent e48f093d6b
commit 9b04e88b72
2 changed files with 10 additions and 2 deletions

View file

@ -115,8 +115,9 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
if err != nil { if err != nil {
return err return err
} }
// Send the email // Send the email
err = sendMail(SendMailTplData{ sendMailTplData := SendMailTplData{
From: "alice@resdigita.org", From: "alice@resdigita.org",
To: user.OtherMailbox, To: user.OtherMailbox,
RelTemplatePath: "user/mail.txt", RelTemplatePath: "user/mail.txt",
@ -125,7 +126,13 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
"SebAddress": "https://www.gvoisins.org", "SebAddress": "https://www.gvoisins.org",
"Code": "...", "Code": "...",
}, },
}) }
err = sendMail(sendMailTplData)
if err != nil {
log.Printf("add(user) sendMail: %v", err)
log.Printf("add(user) sendMail: %v", user)
log.Printf("add(user) sendMail: %v", sendMailTplData)
}
return err return err
} }

View file

@ -54,6 +54,7 @@ func suggestPassword() string {
// Sends an email according to the enclosed information // Sends an email according to the enclosed information
func sendMail(sendMailTplData SendMailTplData) error { func sendMail(sendMailTplData SendMailTplData) error {
log.Printf("sendMail")
templateMail := template.Must(template.ParseFiles(templatePath + "/" + sendMailTplData.RelTemplatePath)) templateMail := template.Must(template.ParseFiles(templatePath + "/" + sendMailTplData.RelTemplatePath))
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
err := templateMail.Execute(buf, sendMailTplData) err := templateMail.Execute(buf, sendMailTplData)