mailer

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

README

mailer

GitHub tag (latest SemVer) Go Reference License

Tests CodeQL Analysis GolangCI Lint Go Report Card

Mailer is an email queue processor that exemplifies provider-agnostic versatility in its design. It's a robust and scalable system tailored for efficient email handling in distributed environments. While maintaining a neutral stance towards various email providers ensuring adaptability and flexibility, Mailer includes a basic adapter implementation for the Postmarkapp email service that can be an example for your implementations or help you to start quickly.

Features

  • Provider-agnostic: Mailer is designed to be provider-agnostic, meaning it can be used with any email service provider.
  • Scalable: Mailer is built to be scalable, allowing you to handle a large number of emails.
  • Email Templates: Mailer provides a ready-to-use template system for email messages based on Arcon Framework
  • Email Queue: Mailer provides a ready-to-use queue system for email messages. It allows you to send emails in the background.

Usage

See the _example directory for usage examples.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	SendEmailTask = "mailer.send_email" // SendEmailTask is a task name for sending an email.
)

Predefined task names.

Variables

View Source
var (
	ErrInvalidTaskPayload     = errors.New("invalid task payload")
	ErrFailedToSendEmail      = errors.New("failed to send email")
	ErrFailedToMarshalPayload = errors.New("failed to marshal payload")
	ErrFailedToEnqueueTask    = errors.New("failed to enqueue task")
	ErrMissingEmail           = errors.New("recipient email address must not be empty")
	ErrMissingSubject         = errors.New("email subject must not be empty")
	ErrMissingHTMLBody        = errors.New("email body cannot be empty")
)

Predefined errors.

Functions

func SendEmailHandler added in v0.2.0

func SendEmailHandler(mail emailAdapter) asyncer.TaskHandler

SendEmailHandler is a function that returns a task handler for sending emails. It takes a mail emailAdapter as a parameter and returns a asyncer.TaskHandler. See details about asyncer module at github.com/dmitrymomot/asyncer. The TaskHandler is responsible for executing the SendEmailTask with the given payload. It sends an email using the provided mail adapter and returns an error if the email fails to send.

Types

type Attachment

type Attachment struct {
	// Name: attachment name
	Name string `json:"name,omitempty"`
	// Content: Base64 encoded attachment data
	Content string `json:"content,omitempty"`
	// ContentType: attachment MIME type
	ContentType string `json:"content_type,omitempty"`
	// ContentId: populate for inlining images with the images cid
	ContentID string `json:"content_id,omitempty"`
}

Attachment is an optional encoded file to send along with an email

type Enqueuer

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

Enqueuer is a helper struct for enqueuing email tasks. It encapsulates the worker.Enqueuer struct and adds queue methods. See pkg/worker/enqueuer.go.

func NewEnqueuer

func NewEnqueuer(e workerEnqueuer) *Enqueuer

NewEnqueuer creates a new email enqueuer.

func (*Enqueuer) SendEmail

func (e *Enqueuer) SendEmail(ctx context.Context, payload SendEmailPayload) error

SendEmail enqueues a task to send an email. It implements the emailAdapter interface. So, it can be used as a mailer adapter in your application. This function returns an error if the task could not be enqueued.

type SendEmailPayload

type SendEmailPayload struct {
	// Email is the email address of the recipient.
	Email string `json:"email,omitempty"`
	// Subject is the subject of the email.
	Subject string `json:"subject,omitempty"`
	// HTMLBody is the HTML body of the email.
	HTMLBody string `json:"html_body,omitempty"`
	// Attachments is an optional encoded file to send along with an email (see Attachment).
	Attachments []Attachment `json:"attachments,omitempty"`
}

SendEmailPayload is a payload for SendEmailTask.

func (SendEmailPayload) Validate added in v0.2.0

func (p SendEmailPayload) Validate() error

Validate validates the SendEmailPayload.

Directories

Path Synopsis
adapters
mocks
templ: version: v0.2.543
templ: version: v0.2.543
components
templ: version: v0.2.543
templ: version: v0.2.543

Jump to

Keyboard shortcuts

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