77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/dnoulet/go-first/internal/model"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type MockEmailService struct{}
|
|
|
|
func NewMockEmailService() *MockEmailService {
|
|
return &MockEmailService{}
|
|
}
|
|
|
|
func (m *MockEmailService) SendContactNotification(submission *model.ContactSubmission) error {
|
|
log.Info().
|
|
Str("to", "daniel.noulet@urpi.be").
|
|
Str("subject", "New Contact Form Submission: "+submission.Subject).
|
|
Str("from_name", submission.Name).
|
|
Str("from_email", submission.Email).
|
|
Msg("Sending contact notification email (mock)")
|
|
return nil
|
|
}
|
|
|
|
func (m *MockEmailService) SendAutoReply(submission *model.ContactSubmission) error {
|
|
log.Info().
|
|
Str("to", submission.Email).
|
|
Str("subject", "Re: "+submission.Subject).
|
|
Msg("Sending auto-reply email (mock)")
|
|
return nil
|
|
}
|
|
|
|
type SMTPEmailService struct {
|
|
host string
|
|
port int
|
|
username string
|
|
password string
|
|
from string
|
|
fromName string
|
|
}
|
|
|
|
func NewSMTPEmailService(host string, port int, username, password, from, fromName string) *SMTPEmailService {
|
|
return &SMTPEmailService{
|
|
host: host,
|
|
port: port,
|
|
username: username,
|
|
password: password,
|
|
from: from,
|
|
fromName: fromName,
|
|
}
|
|
}
|
|
|
|
func (s *SMTPEmailService) SendContactNotification(submission *model.ContactSubmission) error {
|
|
log.Info().
|
|
Str("to", "daniel.noulet@urpi.be").
|
|
Str("subject", "New Contact Form Submission: "+submission.Subject).
|
|
Msg("Sending contact notification email via SMTP")
|
|
return nil
|
|
}
|
|
|
|
func (s *SMTPEmailService) SendAutoReply(submission *model.ContactSubmission) error {
|
|
log.Info().
|
|
Str("to", submission.Email).
|
|
Str("subject", "Re: "+submission.Subject).
|
|
Msg("Sending auto-reply email via SMTP")
|
|
return nil
|
|
}
|
|
|
|
func (s *SMTPEmailService) sendEmail(ctx context.Context, to, subject, body string) error {
|
|
log.Debug().
|
|
Str("to", to).
|
|
Str("subject", subject).
|
|
Msg("Sending email via SMTP")
|
|
return fmt.Errorf("SMTP not implemented")
|
|
}
|