initial commit
This commit is contained in:
commit
e7987e88a7
70 changed files with 13661 additions and 0 deletions
77
internal/service/email_service.go
Normal file
77
internal/service/email_service.go
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
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", "contact@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", "contact@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")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue