mail

package
v0.0.0-...-aebc479 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MTABINARY = "sendmail"

MTABINARY sets the default MTA binary to exec when sending mail locally. sendmail is supported by sendmail and postfix

Variables

This section is empty.

Functions

func CreateMailFromItem

func CreateMailFromItem(from string, to mail.Address, item *gofeed.Item) *gomail.Message

CreateMailFromItem returns a Message containing the given item.

func FormatMessageBody

func FormatMessageBody(story *gofeed.Item) string

FormatMessageBody formats the Story for better reading in a mail client.

Types

type CommandRunner

type CommandRunner interface {
	//	Run([]byte) ([]byte, error)
	Run(from string, to []string, msg []byte) error
}

CommandRunner is the interface for running an external command (to send mail).

type Dispatcher

type Dispatcher struct {
	OutgoingMail chan *Request
	FromAddress  string
	MailSender   Sender
}

Dispatcher listens for mail Requests and sends them to the configured Sender

func CreateAndStartMailer

func CreateAndStartMailer(config *config.Config) *Dispatcher

CreateAndStartMailer returns a New Dispatcher with a sender cofigured from the config file.

func CreateAndStartStubMailer

func CreateAndStartStubMailer() *Dispatcher

CreateAndStartStubMailer returns a Dispatcher that will send all mail to null. For testing.

func NewDispatcher

func NewDispatcher(fromAddress string, sender Sender) *Dispatcher

NewDispatcher returns a newly created Dispatcher with defaults set.

func (*Dispatcher) DispatchLoop

func (d *Dispatcher) DispatchLoop()

DispatchLoop start an infinite loop listening for MailRequests and handling them.

type LocalMTASender

type LocalMTASender struct {
	Runner CommandRunner
}

LocalMTASender can send mail using a local binary (rather than over SMTP)

func NewLocalMTASender

func NewLocalMTASender(mtaPath string) *LocalMTASender

NewLocalMTASender returns a pointer to a new LocalMTASender instance with defaults set.

func (*LocalMTASender) SendMail

func (sender *LocalMTASender) SendMail(msg *gomail.Message) error

SendMail sends mail using a local binary

type NullMailSender

type NullMailSender struct {
	Count int
}

NullMailSender doesn't send mail. It does record the number of times it has been called which is useful for testing.

func (*NullMailSender) SendMail

func (sender *NullMailSender) SendMail(m *gomail.Message) error

SendMail increments a counter for checking in tests.

type Request

type Request struct {
	Item       *gofeed.Item
	Addresses  []mail.Address
	ResultChan chan error
}

Request defines a request for a Feed Item to be mailed to a list of email addresses

type SMTPSender

type SMTPSender struct {
	Hostname string
	Port     int
	Username string
	Password string
	// contains filtered or unexported fields
}

SMTPSender encapsualtes functionality to send mail to a SMTP server

func (*SMTPSender) SendMail

func (s *SMTPSender) SendMail(msg *gomail.Message) error

SendMail sends the given message to the configured server.

It does no batching or delay and just sends immediately.

type Sender

type Sender interface {
	SendMail(*gomail.Message) error
}

Sender is the interface for something that can send mail. The argument is a two dimensional array of messages grouped by Feed Item. This is to allow reporting back of which items were successfully sent.

func NewSMTPSender

func NewSMTPSender(server string, port int, username string, password string) Sender

NewSMTPSender returns a pointer to a new SMTPSender instance with defaults set.

type SendmailRunner

type SendmailRunner struct {
	SendmailPath string
}

SendmailRunner sends email through the sendmail binary

func (SendmailRunner) Run

func (r SendmailRunner) Run(from string, to []string, msg []byte) error

Run sends the given byte array to sendmail over the command line.

Jump to

Keyboard shortcuts

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