email

package
Version: v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package email is logic for sending email invitations

Package email is logic for sending email invitations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ProviderType ProviderType

	User     string `env:"EMAIL_USER"`
	Password string `env:"EMAIL_PASSWORD" json:"-"` // ignored by zap's JSON formatter
	SMTPHost string `env:"EMAIL_SMTP_HOST"`

	// SMTPPort defines the email port to connect to.
	// Note: legacy email port 25 is blocked on GCP and many other systems.
	SMTPPort string `env:"EMAIL_SMTP_PORT, default=587"`

	// Secrets is the secret configuration. This is used to resolve values that
	// are actually pointers to secrets before returning them to the caller. The
	// table implementation is the source of truth for which values are secrets
	// and which are plaintext.
	Secrets secrets.Config
}

Config represents the env var based configuration for email SMTP server connection.

Note: This will only work with email providers that accept external connections.

    The provider must accept TLS, and users should independently consider the security
    of the email provider / account.
Gmail or Google Workspace accounts can be used with an app-password, but will
not work with security features such as Advanced Protection enabled.

func (*Config) HasSMTPCreds

func (c *Config) HasSMTPCreds() bool

HasSMTPCreds returns true if required fields for connecting to SMTP are set.

type NoopProvider

type NoopProvider struct{}

NoopProvider is an email sender that logs without taking any actions.

func (*NoopProvider) From added in v0.12.1

func (s *NoopProvider) From() string

From returns who the invitation should be send from.

func (*NoopProvider) SendEmail added in v0.12.1

func (s *NoopProvider) SendEmail(ctx context.Context, toEmail string, message []byte) error

SendEmail sends a password reset email to the user.

type Provider

type Provider interface {
	// SendEmail sends an email with the given message.
	SendEmail(ctx context.Context, toEmail string, message []byte) error

	// From returns who shown as the sender of the email.
	From() string
}

Provider is an interface for email-sending mechanisms.

func NewNoop

func NewNoop() Provider

NewNoop returns No-op provider

func NewSMTP

func NewSMTP(ctx context.Context, user, password, host, port string) Provider

NewSMTP creates a new Smtp email sender with the given auth.

func ProviderFor

func ProviderFor(ctx context.Context, c *Config) (Provider, error)

ProviderFor creates an email provider given a Config.

type ProviderType

type ProviderType string

ProviderType represents a type of email provider.

const (
	// ProviderTypeNoop is a no-op provider
	ProviderTypeNoop ProviderType = "NOOP"

	// ProviderTypeSMTP composes emails and sends them via an external SMTP server.
	ProviderTypeSMTP ProviderType = "SIMPLE_SMTP"
)

type SMTPProvider

type SMTPProvider struct {
	User     string
	Password string
	SMTPHost string
	SMTPPort string
}

SMTPProvider sends messages via an external SMTP server.

func (*SMTPProvider) From added in v0.12.1

func (s *SMTPProvider) From() string

From returns who shown as the sender of the email.

func (*SMTPProvider) SendEmail added in v0.12.1

func (s *SMTPProvider) SendEmail(ctx context.Context, toEmail string, message []byte) error

SendEmail sends an email to the user.

Jump to

Keyboard shortcuts

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