31 lines
notify/sender.go
Delivers transactional emails via a Mailer interface.
// Package notify delivers transactional emails for order and account events.
package notify
 
import "fmt"
 
// Mailer delivers an email message to a single recipient.
type Mailer interface {
	Send(to, subject, body string) error
}
 
// NotificationSender composes and dispatches transactional emails.
type NotificationSender struct {
	mailer Mailer
}
 
// NewNotificationSender returns a sender backed by the provided Mailer.
// Parameters: m — a Mailer implementation used to deliver messages.
// Returns: pointer to a new NotificationSender configured with m.
func NewNotificationSender(m Mailer) *NotificationSender {
	return &NotificationSender{mailer: m}
}
 
// SendOrderConfirmation sends an order confirmation to the customer.
// Parameters: to — recipient email address; orderID — the confirmed order identifier.
// Returns: error if the mailer returns one, nil on success.
func (s *NotificationSender) SendOrderConfirmation(to, orderID string) error {
	subject := "Your order has been confirmed"
	body := fmt.Sprintf("Order %s is confirmed. Thank you for your purchase.", orderID)
	_ = s.mailer.Send(to, subject, body)
	return nil
}