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 {
return err
}
// Send the email
err = sendMail(SendMailTplData{
sendMailTplData := SendMailTplData{
From: "alice@resdigita.org",
To: user.OtherMailbox,
RelTemplatePath: "user/mail.txt",
@ -125,7 +126,13 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
"SebAddress": "https://www.gvoisins.org",
"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
}

View file

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