emails

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SunriseInviteRE       = "Travel rule compliance exchange requested"
	SunriseInviteTemplate = "sunrise_invite"
)
View Source
const (
	VerifyEmailRE       = "One-time verification code"
	VerifyEmailTemplate = "verify_email"
)

Variables

View Source
var (
	ErrMissingSubject   = errors.New("missing email subject")
	ErrMissingSender    = errors.New("missing email sender")
	ErrMissingRecipient = errors.New("missing email recipient(s)")
	ErrMissingTemplate  = errors.New("missing email template name")
	ErrIncorrectEmail   = errors.New("could not parse email address")
	ErrNotInitialized   = errors.New("email sending method has not been configured")
)
View Source
var (
	ErrConfigMissingSender     = errors.New("invalid configuration: sender email is required")
	ErrConfigInvalidSender     = errors.New("invalid configuration: could not parse sender email address")
	ErrConfigInvalidSupport    = errors.New("invalid configuration: could not parse support email address")
	ErrConfigInvalidCompliance = errors.New("invalid configuration: could not parse compliance email address")
	ErrConfigConflict          = errors.New("invalid configuration: cannot specify configuration for both smtp and sendgrid")
	ErrConfigMissingPort       = errors.New("invalid configuration: smtp port is required")
	ErrConfigPoolSize          = errors.New("invalid configuration: smtp connections pool size must be greater than zero")
	ErrConfigCRAMMD5Auth       = errors.New("invalid configuration: smtp cram-md5 requires username and password")
)

Functions

func Configure

func Configure(conf Config) (err error)

Configure the package to start sending emails. If there is no valid email configuration available then configuration is gracefully ignored without error.

func MustNewSGEmail

func MustNewSGEmail(email string) *sgmail.Email

func MustNewSGEmails

func MustNewSGEmails(emails []string) []*sgmail.Email

func NewSGEmail

func NewSGEmail(email string) (_ *sgmail.Email, err error)

func NewSGEmails

func NewSGEmails(emails []string) (out []*sgmail.Email, err error)

func Render

func Render(name string, data interface{}) (text, html []byte, 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 RenderString

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

func Send

func Send(email *Email) (err error)

Send an email using the configured send methodology. Uses exponential backoff to retry multiple times on error with an increasing delay between attempts.

Types

type Config

type Config struct {
	Sender          string         `split_words:"true" desc:"the email address that messages are sent from"`
	SenderName      string         `split_words:"true" desc:"the name of the sender, usually the name of the VASP or compliance team"`
	SupportEmail    string         `split_words:"true" desc:"the email address to refer support requests to"`
	ComplianceEmail string         `split_words:"true" desc:"the email address to refer compliance requests to"`
	Testing         bool           `split_words:"true" default:"false" desc:"set the emailer to testing mode to ensure no live emails are sent"`
	SMTP            SMTPConfig     `split_words:"true"`
	SendGrid        SendGridConfig `split_words:"false"`
}

The emails config allows users to either send messages via SendGrid or via SMTP.

func (Config) Available

func (c Config) Available() bool

Returns true if either SMTP is configured or SendGrid is.

func (Config) GetSenderName

func (c Config) GetSenderName() string

func (Config) Validate

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

type Email

type Email struct {
	Sender   string
	To       []string
	Subject  string
	Template string
	Data     interface{}
}

func New

func New(recipient, subject, template string, data interface{}) (*Email, error)

New creates a new email template with the currently configured sender attached. If the sender is not configured, then it is left empty; otherwise if the module has been configured and there is no sender, an error is returned.

func NewSunriseInvite

func NewSunriseInvite(recipient string, data SunriseInviteData) (*Email, error)

func NewVerifyEmail

func NewVerifyEmail(recipient string, data VerifyEmailData) (*Email, error)

func (*Email) Send

func (e *Email) Send() error

Helper method to send an email using the emails.Send package function.

func (*Email) ToSMTP

func (e *Email) ToSMTP() (msg *email.Email, err error)

Return an email struct that can be sent via SMTP

func (*Email) ToSendGrid

func (e *Email) ToSendGrid() (msg *sgmail.SGMailV3, err error)

Return an email struct that can be sent via SendGrid

func (*Email) Validate

func (e *Email) Validate() error

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

type SMTPConfig

type SMTPConfig struct {
	Host       string `` /* 139-byte string literal not displayed */
	Port       uint16 `default:"587" desc:"the port to access the smtp server on"`
	Username   string `required:"false" desc:"the username for authentication with the smtp server"`
	Password   string `required:"false" desc:"the password for authentication with the smtp server"`
	UseCRAMMD5 bool   `env:"USE_CRAM_MD5" default:"false" desc:"use CRAM-MD5 auth as defined in RFC 2195 instead of simple authentication"`
	PoolSize   int    `split_words:"true" default:"2" desc:"the smtp connection pool size to use for concurrent email sending"`
}

Configuration for sending emails via SMTP.

func (SMTPConfig) Addr

func (c SMTPConfig) Addr() string

func (SMTPConfig) Auth

func (c SMTPConfig) Auth() smtp.Auth

func (SMTPConfig) Enabled

func (c SMTPConfig) Enabled() bool

func (SMTPConfig) Pool

func (c SMTPConfig) Pool() (*email.Pool, error)

func (SMTPConfig) Validate

func (c SMTPConfig) Validate() (err error)

type SendGridConfig

type SendGridConfig struct {
	APIKey string `split_words:"true" required:"false" desc:"set the sendgrid api key to use sendgrid as the email backend"`
}

Configuration for sending emails using SendGrid.

func (SendGridConfig) Client

func (c SendGridConfig) Client() *sendgrid.Client

func (SendGridConfig) Enabled

func (c SendGridConfig) Enabled() bool

func (SendGridConfig) Validate

func (c SendGridConfig) Validate() (err error)

type SunriseInviteData

type SunriseInviteData struct {
	ContactName     string
	ComplianceName  string
	OriginatorName  string
	BeneficiaryName string
	BaseURL         *url.URL
	Token           sunrise.VerificationToken
	SupportEmail    string
	ComplianceEmail string
}

SunriseInviteData is used to complete the sunrise_invite template.

func (SunriseInviteData) VerifyURL

func (s SunriseInviteData) VerifyURL() string

type VerifyEmailData

type VerifyEmailData struct {
	Code           string
	SupportEmail   string
	ComplianceName string
}

VerifyEmailData is used to send a one-time code to the original email for verification.

Jump to

Keyboard shortcuts

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