websmtp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: AGPL-3.0, AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindHost

func FindHost(addr string) string

FindHost looks for an email address' SMTP host by looking up DNS records and Returns empty string if nothing was found.

Types

type SendRequest

type SendRequest struct {
	From    string   `json:"from" binding:"required"`    // Email source address.
	To      []string `json:"to" binding:"required"`      // List of destination email addresses.
	Subject string   `json:"subject" binding:"required"` // Email subject.
	Body    string   `json:"body" binding:"required"`    // Email body.
}

SendRequest is a request to send an email to the specified 'to' addresses.

type SendStatus

type SendStatus struct {
	ID            string   `json:"id" binding:"required"`     // Email Message-ID header.
	Status        string   `json:"status" binding:"required"` // Request status.
	Failed        []string `json:"failed" binding:"required"` // List of addresses that couldn't be reached.
	TimeCompleted int64    `json:"time_completed"`            // Timestamp at SendRequest completion.
}

SendStatus tracks the status of a SendRequest. If status is "completed", then Failed are the destination addresses that could not be reached.

func SendMail

func SendMail(id string, req SendRequest) SendStatus

SendMail fulfills the SendRequest. This might take a while to complete if you specify too many email addresses. If you need immediate responses, use Sender struct instead.

type Sender

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

Sender maintains a queue of send requests and their status, and attempts to process them.

func NewSender

func NewSender() *Sender

NewSender initializes a new sender.

func (*Sender) Clear

func (s *Sender) Clear()

Clear the SendRequest status cache. Queued requests are not affected, and will show up in the status queue once they're finished processing.

func (*Sender) Enqueue

func (s *Sender) Enqueue(req SendRequest) string

Enqueue a request to the processing queue and return a reference ID. Returns an empty string if req.From is not a valid email address.

func (*Sender) GetStatus

func (s *Sender) GetStatus(ref string) SendStatus

GetStatus returns the status of a request by looking up its reference ID.

func (*Sender) Start

func (s *Sender) Start(n int) error

Start spawns n threads that process the SendRequest queue. Each thread will process one request at a time. Call Stop() to kill the workers.

func (*Sender) Stop

func (s *Sender) Stop() error

Stop any threads currently processing the queue. Returns an error if the sender was never started.

Jump to

Keyboard shortcuts

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