mailer

package
v4.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: AGPL-3.0 Imports: 33 Imported by: 0

README

Mailer Service

Generic service to send email. Encapsulates various implementations, currently :

  • SMTP server connection
  • SendMail call to sendmail on the command line
  • SendGrid Call to Sendgrid API

Queue

TODO: a queue mechanism to avoid spamming mail server should be implemented to batch emails.

GRPC and REST Services

A grpc service is used internally by other services to send email, e.g. by the Activity Service when sending user alerts or user digests, or the Scheduler service to send jobs results to Administrator, etc.

A REST service is exposed to the frontend to allow direct communication between users.

Documentation

Overview

Package mailer acts a central mail server for the application.

It implements various types of communication with actual mail servers (sendmail, smtp, sendgrid API) and a simple queue mechanism to avoid spamming these servers.

Index

Constants

View Source
const (
	// MaxSendRetries defines number of retries in case of connection failure.
	MaxSendRetries = 5
)

Variables

This section is empty.

Functions

func MigrateQueue

func MigrateQueue(from dao.DAO, to dao.DAO, dryRun bool, status chan dao.MigratorStatus) (map[string]int, error)

MigrateQueue is a MigratorFunc to move queued emails from one Queue to another.

func NewGomailMessage

func NewGomailMessage(email *mailer.Mail) (*gomail.Message, error)

NewGomailMessage prepares a new Message to be sent.

func NewQueueDAO

func NewQueueDAO(ctx context.Context, o dao.DAO) (dao.DAO, error)

Types

type BoltQueue

type BoltQueue struct {
	boltdb.DAO
}

BoltQueue defines a queue for the mails backed by a Bolt DB.

func (*BoltQueue) Close

func (b *BoltQueue) Close(ctx context.Context) error

Close closes the DB and delete corresponding file if deleteOnClose flag as been set on creation.

func (*BoltQueue) Consume

func (b *BoltQueue) Consume(sendHandler func(email *mailer.Mail) error) error

Consume acquires the lock and send mails that are in the queue by batches, sending at most 100 mails by batch.

func (*BoltQueue) Init

func (b *BoltQueue) Init(ctx context.Context, cfg configx.Values) error

func (*BoltQueue) Push

func (b *BoltQueue) Push(email *mailer.Mail) error

Push acquires the lock and add a mail to be sent in the queue.

type NoOpSender

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

func (*NoOpSender) Check

func (n *NoOpSender) Check(ctx context.Context) error

func (*NoOpSender) Configure

func (n *NoOpSender) Configure(ctx context.Context, conf configx.Values) error

func (*NoOpSender) Send

func (n *NoOpSender) Send(email *mailer.Mail) error

type Queue

type Queue interface {
	dao.DAO
	Push(email *mailer.Mail) error
	Consume(func(email *mailer.Mail) error) error
	Close(ctx context.Context) error
}

type SendGrid

type SendGrid struct {
	ApiKey string
}

SendGrid is a passerelle to Sendgrid API. It holds the application API Key.

func (*SendGrid) Check

func (s *SendGrid) Check(ctx context.Context) error

func (*SendGrid) Configure

func (s *SendGrid) Configure(ctx context.Context, config configx.Values) error

Configure expects a valid sendgrid API key.

func (*SendGrid) Send

func (s *SendGrid) Send(email *mailer.Mail) error

Send performs the real code to the sendgrid API.

type Sender

type Sender interface {
	Configure(ctx context.Context, conf configx.Values) error
	Send(email *mailer.Mail) error
	Check(ctx context.Context) error
}

func GetSender

func GetSender(ctx context.Context, t string, conf configx.Values) (Sender, error)

type Sendmail

type Sendmail struct {
	BinPath   string
	BinParams []string
}

func (*Sendmail) Check

func (s *Sendmail) Check(ctx context.Context) error

func (*Sendmail) Configure

func (s *Sendmail) Configure(ctx context.Context, conf configx.Values) error

func (*Sendmail) Send

func (d *Sendmail) Send(email *mailer.Mail) error

type Smtp

type Smtp struct {
	User               string
	Password           string
	Host               string
	Port               int
	LocalName          string
	InsecureSkipVerify bool
	UseSSL             bool
}

func (*Smtp) Check

func (gm *Smtp) Check(ctx context.Context) error

func (*Smtp) Configure

func (gm *Smtp) Configure(ctx context.Context, conf configx.Values) error

func (*Smtp) Send

func (gm *Smtp) Send(email *mailer.Mail) error

type StoredEmail

type StoredEmail struct {
	ID    string `bson:"id"`
	Ts    int64  `bson:"ts"`
	Email *mailer.Mail
}

Directories

Path Synopsis
Package grpc provides the actual logic for posting emails to queue or to mail servers
Package grpc provides the actual logic for posting emails to queue or to mail servers
Package lang provides i18n strings for mailer-related data.
Package lang provides i18n strings for mailer-related data.
Package rest exposes a simple API for posting emails
Package rest exposes a simple API for posting emails
Package templates defines ready-to-use templates to send email in a nice formatting.
Package templates defines ready-to-use templates to send email in a nice formatting.

Jump to

Keyboard shortcuts

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