rideaware-api/services/email_service.go
Cipher Vance 3d9de8ba11 feat: add user service layer with business logic
- Create services/user_service.go with user creation and verification
- Add input validation for username, email, and password
- Implement duplicate user checking and password hashing
- Add comprehensive error handling and logging
2025-09-18 20:06:36 -05:00

34 lines
776 B
Go

package services
import (
"fmt"
"net/smtp"
"os"
)
type EmailService struct {
smtpHost string
smtpPort string
smtpUser string
smtpPassword string
}
func NewEmailService() *EmailService {
return &EmailService{
smtpHost: os.Getenv("SMTP_SERVER"),
smtpPort: os.Getenv("SMTP_PORT"),
smtpUser: os.Getenv("SMTP_USER"),
smtpPassword: os.Getenv("SMTP_PASSWORD"),
}
}
func (e *EmailService) SendEmail(to, subject, body string) error {
from := e.smtpUser
msg := fmt.Sprintf("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s", from, to, subject, body)
auth := smtp.PlainAuth("", e.smtpUser, e.smtpPassword, e.smtpHost)
addr := fmt.Sprintf("%s:%s", e.smtpHost, e.smtpPort)
return smtp.SendMail(addr, auth, from, []string{to}, []byte(msg))
}