emails

package
v0.5.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownDate = "unknown date"
	DateFormat  = "Monday, January 2, 2006"
)
View Source
const (
	WelcomeRE     = "Welcome to Ensign!"
	VerifyEmailRE = "Please verify your email address to login to Ensign"
)

Email subject lines

Variables

View Source
var (
	ErrMissingSubject   = errors.New("missing email subject")
	ErrMissingSender    = errors.New("missing email sender")
	ErrMissingRecipient = errors.New("missing email recipient")
)

Functions

func AttachJSON added in v0.4.0

func AttachJSON(message *mail.SGMailV3, data []byte, filename string) (err error)

AttachJSON by marshaling the specified data into human-readable data and encode and attach it to the email as a file.

func LoadAttachment added in v0.4.0

func LoadAttachment(message *mail.SGMailV3, attachmentPath string) (err error)

LoadAttachment onto email from a file on disk.

func Render added in v0.4.0

func Render(name string, data interface{}) (text, html string, err error)

Render returns the text and html executed templates for the specified name and data. Ensure that the extension is not supplied to the render method.

func VerifyEmail added in v0.5.0

func VerifyEmail(data VerifyEmailData) (message *mail.SGMailV3, err error)

VerifyEmail creates an email to verify a user's email address

func WelcomeEmail added in v0.4.0

func WelcomeEmail(data WelcomeData) (message *mail.SGMailV3, err error)

WelcomeEmail creates a welcome email for a new user

Types

type Config

type Config struct {
	APIKey       string `split_words:"true" required:"false"`
	FromEmail    string `split_words:"true" default:"ensign@rotational.io"`
	AdminEmail   string `split_words:"true" default:"admins@rotational.io"`
	EnsignListID string `split_words:"true" required:"false"`
	Testing      bool   `split_words:"true" default:"false"`
	Archive      string `split_words:"true"`
}

Configures SendGrid for sending emails and managing marketing contacts.

func (Config) Enabled

func (c Config) Enabled() bool

Returns true if there is a SendGrid API key available

func (Config) Validate

func (c Config) Validate() (err error)

From and admin emails are required if the SendGrid API is enabled.

type EmailData added in v0.4.0

type EmailData struct {
	Subject   string
	Sender    sendgrid.Contact
	Recipient sendgrid.Contact
}

EmailData includes data fields that are common to all the email builders such as the subject and sender/recipient information.

func (EmailData) Build added in v0.4.0

func (e EmailData) Build(text, html string) (msg *mail.SGMailV3, err error)

Build creates a new email from pre-rendered templates.

func (EmailData) Validate added in v0.4.0

func (e EmailData) Validate() error

Validate that all required data is present to assemble a sendable email.

type EmailManager

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

EmailManager allows a server to send rich emails using the SendGrid service.

func New

func New(conf Config) (m *EmailManager, err error)

New email manager with the specified configuration.

func (*EmailManager) AddContact added in v0.4.0

func (m *EmailManager) AddContact(contact *sg.Contact, listIDs ...string) (err error)

AddContact adds a contact to SendGrid, adding them to the Ensign marketing list if it is configured. This is an upsert operation so existing contacts will be updated. The caller can optionally specify additional lists that the contact should be added to. If no lists are configured or specified, then the contact is added or updated in SendGrid but is not added to any marketing lists.

func (*EmailManager) Send

func (m *EmailManager) Send(message *sgmail.SGMailV3) (err error)

type SendGridClient

type SendGridClient interface {
	Send(email *sgmail.SGMailV3) (*rest.Response, error)
}

SendGridClient is an interface that can be implemented by live email clients to send real emails or by mock clients for testing.

type VerifyEmailData added in v0.5.0

type VerifyEmailData struct {
	EmailData
	FullName  string
	VerifyURL string
}

VerifyEmailData is used to complete the verify email template

type WelcomeData added in v0.4.0

type WelcomeData struct {
	EmailData
	FirstName    string
	LastName     string
	Email        string
	Organization string
	Domain       string
}

WelcomeData is used to complete the welcome email template

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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