From 7eedf221d57f5f6e3b5eead6eb370467ef53af7e Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Sun, 23 Jul 2023 09:16:17 +0200 Subject: [PATCH] G Pas --- gpas.go | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/gpas.go b/gpas.go index e918ec9..dd89a2c 100644 --- a/gpas.go +++ b/gpas.go @@ -5,14 +5,14 @@ gpas is GVoisin password reset package main import ( - "bytes" "errors" "fmt" - "html/template" "log" - "github.com/emersion/go-sasl" - "github.com/emersion/go-smtp" + // "github.com/emersion/go-sasl" + // "github.com/emersion/go-smtp" + "net/smtp" + "github.com/go-ldap/ldap/v3" // "strings" ) @@ -46,22 +46,24 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error { return errors.New("Il n'y a pas d'utilisateur qui correspond") } // Préparation du courriel à envoyer - code := "GPas" - templateMail := template.Must(template.ParseFiles(templatePath + "/invite_mail.txt")) - buf := bytes.NewBuffer([]byte{}) - templateMail.Execute(buf, &CodeMailFields{ - To: user.OtherMailbox, - From: config.MailFrom, - InviteFrom: "GPas", - Code: code, - WebBaseAddress: config.WebAddress, - }) + // code := "GPas" + // templateMail := template.Must(template.ParseFiles(templatePath + "/invite_mail.txt")) + // buf := bytes.NewBuffer([]byte{}) + // templateMail.Execute(buf, &CodeMailFields{ + // To: user.OtherMailbox, + // From: config.MailFrom, + // InviteFrom: "GPas", + // Code: code, + // WebBaseAddress: config.WebAddress, + // }) + message := []byte("Hi " + user.OtherMailbox) log.Printf("Sending mail to: %s", user.OtherMailbox) - var auth sasl.Client = nil - if config.SMTPUsername != "" { - auth = sasl.NewPlainClient("", config.SMTPUsername, config.SMTPPassword) - } - err = smtp.SendMail(config.SMTPServer, auth, config.MailFrom, []string{user.OtherMailbox}, buf) + // var auth sasl.Client = nil + // if config.SMTPUsername != "" { + // auth = sasl.NewPlainClient("", config.SMTPUsername, config.SMTPPassword) + // } + auth := smtp.PlainAuth("", config.SMTPUsername, config.SMTPPassword, config.SMTPServer) + err = smtp.SendMail(config.SMTPServer+":587", auth, config.SMTPUsername, []string{user.OtherMailbox}, message) if err != nil { return err }