emailservices

package
v0.0.0-...-6aee27a Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailJob

type EmailJob struct {
	From        string
	To          string
	Subject     string
	Body        string
	HTMLBody    string
	OnCompleted func(error)
}

EmailJob is a structure representing the required information needed to send a single email all other information should be specific to the email servicer, and should be provided to it in its configuration

type EmailServicer

type EmailServicer interface {
	AddToQueue(EmailJob) error
}

EmailServicer is a simple interface for others to send emails. Once called, the expectation is that the email will eventually be sent, and called the OnCompleted when the email is sent, or fails to be sent

type EmailServicerType

type EmailServicerType = string

EmailServicerType acts as an enum for selecting known email servicers types

const (
	// StdOutEmailer refers to an email servicer that simply outputs the emails to the terminal.
	// Useful for local testing
	StdOutEmailer EmailServicerType = "stdout"

	// MemoryEmailer refers to an email servicer that holds all emails sent in memory.
	// Useful for unit testing
	MemoryEmailer EmailServicerType = "memory"

	// SMTPEmailer refers to an email servicer that sends emails via SMTP.
	SMTPEmailer EmailServicerType = "smtp"
)

type MemoryMailer

type MemoryMailer struct {
	Outbox map[string][]EmailJob // emails stored as To address : [emails, ...]
	// contains filtered or unexported fields
}

MemoryMailer is an EmailServicer that holds all of the emails it receives in memory. This mailer is designed to be used with testing, where the caller can quickly check if the email details were received correctly

func MakeMemoryMailer

func MakeMemoryMailer(logger logging.Logger) MemoryMailer

MakeMemoryMailer constructs a MemoryMailer

func (*MemoryMailer) AddToQueue

func (m *MemoryMailer) AddToQueue(job EmailJob) error

AddToQueue adds the given email job to memory (specifically, to the MemoryMailer.Outbox) this will never return an error, nor call OnCompleted with an error (but OnCompleted _will_ still be called)

type SMTPEmailAuthType

type SMTPEmailAuthType string

SMTPEmailAuthType indicates how the system should authenticate with the STMP server see: https://www.samlogic.net/articles/smtp-commands-reference-auth.htm

const (
	// LoginType indicates the login SMTP authentication flow
	LoginType SMTPEmailAuthType = "login"
	// PlainType indicates the plain SMTP authentication flow
	PlainType SMTPEmailAuthType = "plain"
	// CRAMMD5Type  indicates the CRAM-MD5 SMTP authentication flow
	CRAMMD5Type SMTPEmailAuthType = "crammd5"
)

type SMTPMailer

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

SMTPMailer is the struct that holds an email servicer that sends emails over SMTP

func MakeSMTPMailer

func MakeSMTPMailer(logger logging.Logger) SMTPMailer

MakeSMTPMailer constructs an SMTPMailer with the given logger

func (*SMTPMailer) AddToQueue

func (m *SMTPMailer) AddToQueue(job EmailJob) error

AddToQueue attempts to send the provided email over smtp

type WriterMailer

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

WriterMailer acts as a no-email email server for monitoring when running locally. All emails are printed to the provided writer. This is intended to be used with os.Stdout, but any writer should work

func MakeWriterMailer

func MakeWriterMailer(w io.Writer, logger logging.Logger) WriterMailer

MakeWriterMailer constructs a WriterMailer

func (*WriterMailer) AddToQueue

func (m *WriterMailer) AddToQueue(job EmailJob) error

AddToQueue writes the email to the writer provided in MakeWriterMailer returns an error if the underlying template cannot be executed

Jump to

Keyboard shortcuts

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