mail

package
v0.0.0-...-7a9e484 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package dish provides services and types for sending mails.

Package dish provides services and types for sending mails.

Index

Constants

View Source
const (
	FromName string = "FoodUnit"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service executes mail-related business logic and use cases. It is also responsible for accessing the model storage under consideration of all business rules.

func New

func New(sgAPIKey string, u storage.User) *Service

NewService creates a new Service instance utilizing the given storage objects. The storage objects need to be ready to use for the service.

func (*Service) Send

func (s *Service) Send(settings *Settings) error

Send creates an e-mail and attempts to send it via the SendGrid API. It will replace all placeholders of Settings.Variables in the mail subject and body.

For instance, the subject may look like this: `Welcome to FoodUnit, {{name}}!` To replace {{name}} with a real value, you should provide settings like this:

settings := mail.Settings{
	Subject: `Welcome to FoodUnit, {{name}}!`,
	Variables: map[string]string{
		"name": username,
	}
}

mailService.Send(&settings)

Send will automatically replace the map key with the associated value. Note that the key must not include the curly brackets.

type Settings

type Settings struct {
	From      string            `json:"from"`
	To        string            `json:"to"`
	ToName    string            `json:"to_name"`
	Subject   string            `json:"subject"`
	Body      string            `json:"body"`
	Variables map[string]string `json:"variables"`
}

Settings provides basic configuration values for sending an e-mail. It also holds placeholders which will be replaced with the mapped values.

Jump to

Keyboard shortcuts

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