This repository has been archived on 2025-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
web-app-template/service/mail.go
Tim Wundenberg a70138f2f7
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
fix: restructure env handling for better testing capabillities #181
2024-09-29 23:55:47 +02:00

30 lines
737 B
Go

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))
}