Documentation
¶
Overview ¶
Package email provides an interface and implementations for sending emails.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsoleEmailSender ¶
ConsoleEmailSender logs emails to a writer (default: stdout) for development.
func NewConsoleEmailSender ¶
func NewConsoleEmailSender() *ConsoleEmailSender
NewConsoleEmailSender creates a new ConsoleEmailSender that writes to stdout. Useful for development to see emails in the console.
Example:
sender := email.NewConsoleEmailSender()
sender.Send("user@example.com", "Welcome", "Hello!")
func (*ConsoleEmailSender) Send ¶
func (s *ConsoleEmailSender) Send(to, subject, body string) error
Send logs the email to the configured writer.
type EmailSender ¶
EmailSender is the interface for sending emails.
func NewEmailSenderFromEnv ¶
func NewEmailSenderFromEnv() (EmailSender, error)
NewEmailSenderFromEnv creates an EmailSender based on the EMAIL_PROVIDER environment variable.
Supported providers:
"console" (default) - logs emails to stdout (development) "smtp" - sends via SMTP server (production) "noop" - discards silently (testing)
type NoopEmailSender ¶
type NoopEmailSender struct{}
NoopEmailSender discards all emails silently. Useful for testing when you don't want email output.
func NewNoopEmailSender ¶
func NewNoopEmailSender() *NoopEmailSender
NewNoopEmailSender creates a new NoopEmailSender.
Example:
sender := email.NewNoopEmailSender()
sender.Send("user@example.com", "Welcome", "Hello!") // Does nothing
func (*NoopEmailSender) Send ¶
func (s *NoopEmailSender) Send(to, subject, body string) error
Send does nothing and returns nil.
type SMTPConfig ¶
type SMTPConfig struct {
Host string
Port int
Username string
Password string
From string
FromName string
Timeout time.Duration
}
SMTPConfig holds SMTP connection configuration.
type SMTPEmailSender ¶
type SMTPEmailSender struct {
// contains filtered or unexported fields
}
SMTPEmailSender sends emails via SMTP using the go-mail library. Each Send() call opens a new connection, which is appropriate for low-volume transactional email (auth flows). For high-volume use, consider connection pooling or a dedicated email service.
func NewSMTPEmailSender ¶
func NewSMTPEmailSender(config SMTPConfig) *SMTPEmailSender
NewSMTPEmailSender creates a new SMTP email sender with the given configuration.
func NewSMTPEmailSenderFromEnv ¶
func NewSMTPEmailSenderFromEnv() (*SMTPEmailSender, error)
NewSMTPEmailSenderFromEnv creates an SMTPEmailSender from environment variables.
Required env vars:
SMTP_HOST - SMTP server hostname EMAIL_FROM - Sender email address
Optional env vars:
SMTP_PORT - SMTP server port (default: 587) SMTP_USER - SMTP username SMTP_PASS - SMTP password EMAIL_FROM_NAME - Sender display name
func (*SMTPEmailSender) Send ¶
func (s *SMTPEmailSender) Send(to, subject, body string) error
Send sends a plain-text email via SMTP.