email

package
v3.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package email provides an interface to send messages over email.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterNotification added in v3.19.2

func RegisterNotification(name string, builder *NotificationBuilder)

RegisterNotification registers an email notification on the default registry.

func RegisterTemplate added in v3.19.2

func RegisterTemplate(tmpl *Template)

RegisterTemplate registers a template on the default registry.

func RegisteredNotifications added in v3.19.2

func RegisteredNotifications() []string

RegisteredNotifications returns the names of the registered email notifications in the default registry.

func RegisteredTemplates added in v3.19.2

func RegisteredTemplates() []string

RegisteredTemplates returns the names of the registered templates in the default registry.

Types

type Config

type Config struct {
	SenderConfig `name:",squash"`
	Network      NetworkConfig `name:"network" description:"The network of the sender"`
}

Config is the configuration for sending emails.

type FSTemplate added in v3.19.2

type FSTemplate struct {
	SubjectTemplate      string
	HTMLTemplateBaseFile string
	HTMLTemplateFile     string
	TextTemplateBaseFile string
	TextTemplateFile     string
	IncludePatterns      []string
}

FSTemplate defines the template files to parse from the file system.

type MapNotificationRegistry added in v3.19.2

type MapNotificationRegistry map[string]*NotificationBuilder

MapNotificationRegistry is an email notification registry implementation.

func NewNotificationRegistry added in v3.19.2

func NewNotificationRegistry() MapNotificationRegistry

NewNotificationRegistry returns a new empty email notification registry.

func (MapNotificationRegistry) GetNotification added in v3.19.2

func (reg MapNotificationRegistry) GetNotification(_ context.Context, name string) *NotificationBuilder

GetNotification returns a registered email notification from the registry.

func (MapNotificationRegistry) RegisterNotification added in v3.19.2

func (reg MapNotificationRegistry) RegisterNotification(name string, builder *NotificationBuilder)

RegisterNotification registers an email notification.

func (MapNotificationRegistry) RegisteredNotifications added in v3.19.2

func (reg MapNotificationRegistry) RegisteredNotifications() []string

RegisteredNotifications returns a sorted list of the names of all registered email notifications.

type MapTemplateRegistry added in v3.19.2

type MapTemplateRegistry map[string]*Template

MapTemplateRegistry is a template registry implementation.

func NewTemplateRegistry

func NewTemplateRegistry() MapTemplateRegistry

NewTemplateRegistry returns a new empty template registry.

func (MapTemplateRegistry) GetTemplate added in v3.19.2

func (reg MapTemplateRegistry) GetTemplate(_ context.Context, name string) *Template

GetTemplate returns a registered template from the registry.

func (MapTemplateRegistry) RegisterTemplate added in v3.19.2

func (reg MapTemplateRegistry) RegisterTemplate(tmpl *Template)

RegisterTemplate registers a template.

func (MapTemplateRegistry) RegisteredTemplates added in v3.19.2

func (reg MapTemplateRegistry) RegisteredTemplates() []string

RegisteredTemplates returns a sorted list of the names of all registered templates.

type Message

type Message struct {
	TemplateName string

	RecipientName    string
	RecipientAddress string

	Subject  string
	HTMLBody string
	TextBody string
}

Message for sending over email.

type NetworkConfig added in v3.19.2

type NetworkConfig struct {
	Name              string `name:"name" description:"The name of the network"`
	IdentityServerURL string `name:"identity-server-url" description:"The URL of the Identity Server"`
	ConsoleURL        string `name:"console-url" description:"The URL of the Console"`
	AssetsBaseURL     string `name:"assets-base-url" description:"The base URL to the email assets"`
	BrandingBaseURL   string `name:"branding-base-url" description:"The base URL to the email branding assets"`
}

NetworkConfig is the configuration of the network that sends the emails. This configuration is used by email templates.

type NotificationBuilder added in v3.19.2

type NotificationBuilder struct {
	EmailTemplateName string
	DataBuilder       NotificationTemplateDataBuilder
}

NotificationBuilder is used to build notifications.

func GetNotification added in v3.19.2

func GetNotification(ctx context.Context, name string) *NotificationBuilder

GetNotification returns a registered email notification from the registry in the context (if available), otherwise falling back to the default registry.

type NotificationRegistry added in v3.19.2

type NotificationRegistry interface {
	RegisteredNotifications() []string
	GetNotification(ctx context.Context, name string) *NotificationBuilder
}

NotificationRegistry keeps track of email notifications.

type NotificationTemplateData added in v3.19.2

type NotificationTemplateData interface {
	TemplateData
	Notification() *ttnpb.Notification
	ConsoleURL() string
	Receivers() string
}

NotificationTemplateData extends TemplateData for notifications.

func NewNotificationTemplateData added in v3.19.2

func NewNotificationTemplateData(data TemplateData, notification *ttnpb.Notification) NotificationTemplateData

NewNotificationTemplateData returns new notification template data.

type NotificationTemplateDataBuilder added in v3.19.2

type NotificationTemplateDataBuilder func(context.Context, NotificationTemplateData) (NotificationTemplateData, error)

NotificationTemplateDataBuilder is used to extend NotificationTemplateData.

type Sender

type Sender interface {
	Send(message *Message) error
}

Sender is the interface for sending messages over email.

type SenderConfig added in v3.29.1

type SenderConfig struct {
	SenderName    string `name:"sender-name" description:"The name of the sender"`
	SenderAddress string `name:"sender-address" description:"The address of the sender"`
}

SenderConfig is the configuration of the sender.

type Template added in v3.19.2

type Template struct {
	Name            string
	SubjectTemplate *template.Template
	HTMLTemplate    *template.Template
	TextTemplate    *template.Template
}

Template is the template for an email message.

func GetTemplate added in v3.19.2

func GetTemplate(ctx context.Context, name string) *Template

GetTemplate returns a registered template from the registry in the context (if available), otherwise falling back to the default registry.

func NewTemplateFS added in v3.19.2

func NewTemplateFS(fsys fs.FS, name string, opts FSTemplate) (*Template, error)

NewTemplateFS parses a new email template by reading files on fsys.

func (Template) Execute added in v3.19.2

func (m Template) Execute(data TemplateData) (*Message, error)

Execute the message template, rendering it into a Message.

type TemplateData added in v3.19.2

type TemplateData interface {
	Network() *NetworkConfig
	ConsoleURL() string
	Receiver() *ttnpb.User
	ReceiverName() string
}

TemplateData is the minimal interface Execute needs to render an email template.

func NewTemplateData added in v3.19.2

func NewTemplateData(networkConfig *NetworkConfig, receiver *ttnpb.User) TemplateData

NewTemplateData returns new template data.

type TemplateDataBuilder added in v3.19.2

type TemplateDataBuilder func(context.Context, TemplateData) (TemplateData, error)

TemplateDataBuilder is used to extend TemplateData.

type TemplateRegistry

type TemplateRegistry interface {
	RegisteredTemplates() []string
	GetTemplate(ctx context.Context, name string) *Template
}

TemplateRegistry keeps track of email templates.

Directories

Path Synopsis
Package mock provides a test email provider that is used in tests.
Package mock provides a test email provider that is used in tests.
Package sendgrid provides the implementation of an email sender using SendGrid.
Package sendgrid provides the implementation of an email sender using SendGrid.
Package smtp implements SMTP as email provider.
Package smtp implements SMTP as email provider.
Package templates is responsible for handling the email templates sent by The Things Stack.
Package templates is responsible for handling the email templates sent by The Things Stack.

Jump to

Keyboard shortcuts

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