email

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package email is logic for sending email invitations

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"`
	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) SendNewUserInvitation

func (s *NoopProvider) SendNewUserInvitation(ctx context.Context, toEmail string) error

SendNewUserInvitation sends a password reset email to the user.

type Provider

type Provider interface {
	// SendNewUserInvitation sends an invite to join the server.
	SendNewUserInvitation(ctx context.Context, email string) error
}

Provider is an interface for email-sending mechanisms.

func NewFirebase

func NewFirebase(ctx context.Context) (Provider, error)

NewFirebase creates a new SMTP email sender with the given auth.

func NewNoop

func NewNoop() Provider

NewNoop returns No-op provider

func NewSMTP

func NewSMTP(ctx context.Context, user, password, host, port string, h *render.Renderer, auth *auth.Client) Provider

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

func ProviderFor

func ProviderFor(ctx context.Context, c *Config, h *render.Renderer, auth *auth.Client) (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"

	// ProviderTypeFirebase falls back to firebase's default email template.
	// it uses password-reset rather than a true invitation.
	ProviderTypeFirebase ProviderType = "FIREBASE"

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

type SMTPProvider

type SMTPProvider struct {
	FirebaseAuth *auth.Client

	Renderer *render.Renderer

	User     string
	Password string
	SMTPHost string
	SMTPPort string
}

SMTPProvider sends messages via an external SMTP server.

func (*SMTPProvider) SendNewUserInvitation

func (s *SMTPProvider) SendNewUserInvitation(ctx context.Context, toEmail string) error

SendNewUserInvitation sends a password reset email to the user.

Jump to

Keyboard shortcuts

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