email

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 10 Imported by: 0

README

email — SMTP email sender with MJML templating

import "github.com/downsized-devs/sdk-go/email"

Stability: Stable — see STABILITY.md

Sends transactional email over SMTP, with mustache/MJML templating for the body.

Features

  • SendEmail — SMTP send.
  • GenerateBody — render template + data into HTML.
  • FromHTML, FromMJML — template source helpers.

Installation

go get github.com/downsized-devs/sdk-go/email

Quick Start

mailer := email.Init(email.Config{
    Host: "smtp.example.com", Port: 587,
    Username: "user", Password: "pass",
    From: "no-reply@example.com",
}, log)

body, _ := mailer.GenerateBody().FromMJML("templates/welcome.mjml", map[string]any{"Name": "Alice"})
_ = mailer.SendEmail(ctx, email.Payload{
    To:      []string{"alice@example.com"},
    Subject: "Welcome",
    Body:    body,
})

API Reference

Symbol Signature
Init func Init(cfg Config, log logger.Interface) Interface
Interface.SendEmail (ctx, Payload) error
Interface.GenerateBody () TemplateInterface
TemplateInterface.FromHTML (path string, data any) (string, error)
TemplateInterface.FromMJML (path string, data any) (string, error)

Configuration

Field Required Description
Host, Port yes SMTP endpoint.
Username, Password yes SMTP auth.
From yes Default sender.

Error Handling

Errors are wrapped with codes (email/third-party range).

Dependencies

  • Internal: codes, errors, logger
  • External: gopkg.in/gomail.v2, github.com/Boostport/mjml-go

Testing

go test ./email/...

Two test files cover template rendering and SMTP send (mocked).

Contributing

See CONTRIBUTING.md.

  • parser — for parsing email payloads from external services.
  • logger — required at Init time.

Documentation

Index

Constants

View Source
const (
	BodyContentTypePlain string = "text/plain"
	BodyContentTypeHTML  string = "text/html"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSSESConfig

type AWSSESConfig struct {
	Region          string
	AccessKeyID     string
	SecretAccessKey string
}

type BodyFromHTMLParams

type BodyFromHTMLParams struct {
	Filename          string
	OverrideDirectory string
	Data              any
	FuncMap           map[string]any
}

type BodyFromMJMLParams

type BodyFromMJMLParams struct {
	Filename          string
	OverrideDirectory string
	Data              any
	FuncMap           map[string]any
}

type Config

type Config struct {
	SMTP     SMTPConfig
	Template TemplateConfig
}

type Interface

type Interface interface {
	SendEmail(ctx context.Context, params SendEmailParams) error
	GenerateBody() TemplateInterface
}

func Init

func Init(cfg Config, log logger.Interface) Interface

type Recipient

type Recipient struct {
	ToEmails  []string
	CCEmails  []string
	BCCEmails []string
}

type SMTPConfig

type SMTPConfig struct {
	Host      string
	Port      int
	Username  string
	Password  string
	TLSConfig struct {
		InsecureSkipVerify bool
	}
}

type SendEmailParams

type SendEmailParams struct {
	Body        string
	BodyType    string
	Subject     string
	SenderName  string
	SenderEmail string
	Recipients  Recipient
	Attachments []string
	Headers     map[string]string
}

type TemplateConfig

type TemplateConfig struct {
	FileDirectory string
}

type TemplateInterface

type TemplateInterface interface {
	FromHTML(params BodyFromHTMLParams) (string, error)
	FromMJML(ctx context.Context, params BodyFromMJMLParams) (string, error)
}

Jump to

Keyboard shortcuts

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