fix: restructure env handling for better testing capabillities #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 47s
Build and Push Docker Image / Explore-Gitea-Actions (push) Successful in 55s

This commit was merged in pull request #195.
This commit is contained in:
2024-09-29 23:51:23 +02:00
parent 25e82be339
commit a70138f2f7
15 changed files with 191 additions and 152 deletions

29
service/mail.go Normal file
View File

@@ -0,0 +1,29 @@
package service
import (
"fmt"
"me-fit/types"
"net/smtp"
)
type MailService struct {
serverSettings *types.ServerSettings
}
func NewMailService(serverSettings *types.ServerSettings) MailService {
return MailService{serverSettings: serverSettings}
}
func (m MailService) SendMail(to string, subject string, message string) error {
if m.serverSettings.Smtp == nil {
return nil
}
s := m.serverSettings.Smtp
auth := smtp.PlainAuth("", s.User, s.Pass, s.Host)
msg := fmt.Sprintf("From: %v <%v>\nTo: %v\nSubject: %v\nMIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n%v", s.FromName, s.FromMail, to, subject, message)
return smtp.SendMail(s.Host+":"+s.Port, auth, s.FromMail, []string{to}, []byte(msg))
}