email

package
v0.0.0-...-6669b94 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: GPL-3.0 Imports: 15 Imported by: 1

Documentation

Overview

Package email implements email submission.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidAddress = errors.New("invalid address")

Functions

func AddressValid

func AddressValid(addr string) bool

AddressValid returns true if addr is a well-formed email address, and if it exactly one email address and not a list. Use AddressValid to check the email address in your application.

func MakeEmail

func MakeEmail(from, to, subject string, body []byte) (*bytes.Buffer, error)

Types

type DummyMailer

type DummyMailer struct{}

func (DummyMailer) Send

func (DummyMailer) Send(to string, subject string, body []byte) error

type Emailer

type Emailer interface {
	Send(to string, subject string, body []byte) error
}

type SMTP

type SMTP struct {
	From     string `json:"from"`
	Username string `json:"username"`
	Password string `json:"password"`
	Host     string `json:"host"`
}

SMTP connects to a SMTP server. If the server is not reachable, Send fails.

func LoadSMTP

func LoadSMTP(jsonPath string) (*SMTP, error)

LoadSMTP reads a JSON file and unmarshals it into an SMTP struct. Then it connects and authenticates to the server in order to test the hostname and credentials.

If the file does not exist, an empty file is created:

{"from":"","username":"","password":"","host":""}

func (SMTP) Send

func (mailer SMTP) Send(to string, subject string, body []byte) error

type Sendmail

type Sendmail struct {
	From string
}

Sendmail runs /usr/bin/sendmail to queue an email for sending.

Your sendmail binary probably has the setgid bit set to be able to copy the mail into the queue directory. If your binary runs as a sandboxed systemd service, you might have to disable these options:

LockPersonality
MemoryDenyWriteExecute
PrivateDevices
ProtectClock
ProtectHostname
ProtectKernelLogs
ProtectKernelModules
ProtectKernelTunables
RestrictAddressFamilies
RestrictNamespaces
RestrictRealtime
RestrictSUIDSGID
SystemCallArchitectures
SystemCallFilter
SystemCallLog

Plus you might have to enable writing to the spool directory, for example:

ReadWritePaths=/var/spool/nullmailer

func (Sendmail) Send

func (mailer Sendmail) Send(to string, subject string, body []byte) error

Jump to

Keyboard shortcuts

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