Documentation
¶
Index ¶
- Constants
- Variables
- func Configure(conf Config) (err error)
- func MustNewSGEmail(email string) *sgmail.Email
- func MustNewSGEmails(emails []string) []*sgmail.Email
- func NewSGEmail(email string) (_ *sgmail.Email, err error)
- func NewSGEmails(emails []string) (out []*sgmail.Email, err error)
- func Render(name string, data interface{}) (text, html []byte, err error)
- func RenderString(name string, data interface{}) (text, html string, err error)
- func Send(email *Email) (err error)
- type Config
- type Email
- type SMTPConfig
- type SendGridConfig
- type SunriseInviteData
- type VerifyEmailData
Constants ¶
const ( SunriseInviteRE = "Travel rule compliance exchange requested" SunriseInviteTemplate = "sunrise_invite" )
const ( VerifyEmailRE = "One-time verification code" VerifyEmailTemplate = "verify_email" )
Variables ¶
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") )
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 ¶
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 MustNewSGEmails ¶
func Render ¶
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 ¶
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) GetSenderName ¶
type Email ¶
func New ¶
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) ToSendGrid ¶
Return an email struct that can be sent via SendGrid
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) 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 ¶
VerifyEmailData is used to send a one-time code to the original email for verification.