email

package
v0.0.0-...-52ac860 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package email provides generic email sending functionality.

This package is independent of business logic and can be used by any service that needs to send email notifications. It supports SMTP-based email delivery with optional TLS encryption.

Key features:

  • Simple interface for sending emails
  • Support for both HTML and plain text formats
  • Multiple recipients per message
  • No-op client for testing/development
  • Delivery receipt tracking

Example usage:

config := &email.Config{
    Host:     "smtp.gmail.com",
    Port:     587,
    Username: "user@example.com",
    Password: "password",
    From:     "noreply@example.com",
    UseTLS:   true,
}

client, err := email.NewClient(config)
if err != nil {
    log.Fatal(err)
}

msg := &email.Message{
    ID:     "msg-123",
    Title:  "Test Email",
    Body:   "<h1>Hello World</h1>",
    Format: "html",
    Targets: []email.Target{
        {Type: "email", Value: "recipient@example.com", Platform: "email"},
    },
}

receipt, err := client.Send(context.Background(), msg)
if err != nil {
    log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Send(ctx context.Context, msg *Message) (*Receipt, error)
}

Client provides email sending functionality.

func NewClient

func NewClient(config *Config) (Client, error)

NewClient creates a new email client.

type Config

type Config struct {
	Host     string
	Port     int
	Username string
	Password string
	From     string
	UseTLS   bool
	Timeout  time.Duration
}

Config holds email configuration.

type Message

type Message struct {
	ID       string
	Title    string
	Body     string
	Format   string // "html" or "text"
	Targets  []Target
	Metadata map[string]interface{}
}

Message represents an email message.

type Receipt

type Receipt struct {
	MessageID string
	Results   []Result
}

Receipt represents the result of sending an email.

type Result

type Result struct {
	Platform string
	Success  bool
	Error    string
}

Result represents the result for a single recipient.

type Target

type Target struct {
	Type     string
	Value    string // email address
	Platform string
}

Target represents an email recipient.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL