fix: restructure env handling for better testing capabillities #181
This commit was merged in pull request #195.
This commit is contained in:
29
service/mail.go
Normal file
29
service/mail.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user