feat(auth): #154 send verification mails

This commit is contained in:
2024-09-07 22:51:50 +02:00
parent 5172a30781
commit f6aaccc1aa
13 changed files with 353 additions and 100 deletions

View File

@@ -1,19 +1,15 @@
package utils
import (
"log/slog"
"fmt"
"net/smtp"
)
func SendWelcomeMail(to string) {
func SendMail(to string, subject string, message string) error {
auth := smtp.PlainAuth("", SmtpUser, SmtpPass, SmtpHost)
msg := "From: " + SmtpFromName + " <" + SmtpFromMail + ">\nTo: " + to + "\nSubject: Welcome to me-fit\n\nWelcome to me-fit!"
err := smtp.SendMail(SmtpHost+":"+SmtpPort, auth, SmtpFromMail, []string{to}, []byte(msg))
if err != nil {
slog.Error("Could not send mail: " + err.Error())
}
msg := fmt.Sprintf("From: %v <%v>\nTo: %v\nSubject: %v\nMIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n%v", SmtpFromName, SmtpFromMail, to, subject, message)
return smtp.SendMail(SmtpHost+":"+SmtpPort, auth, SmtpFromMail, []string{to}, []byte(msg))
}