mail

package
v0.16.7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 10 Imported by: 1

README

Mail backend

This is a write-only backend: each uploaded file is sent as an email attachment. Listing directories always returns an empty result.

Parameters

  • Host: The SMTP server.
  • Port (optional): The SMTP port. Defaults to 25.
  • SSL (optional): true to connect with SSL/TLS (SMTPS). Defaults to true on port 465, false otherwise.
  • StartTLSPolicy (optional): MandatoryStartTLS (default), OpportunisticStartTLS or NoStartTLS.
  • Username, Password (optional): The SMTP credentials.
  • Localname (optional): The host name sent in the HELO command.
  • From: The sender address.
  • To: The recipient address.
  • Subject: The subject of the emails.
  • MaxSize (optional): Maximum size of an uploaded file in bytes, 26214400 (25 MiB) by default. Must be positive. Larger uploads are refused and no email is sent.
  • Message: The body of the emails, %s is replaced by the file name.

Configuration

See example.json:

{
  "accesses": [
    {
      "user": "test",
      "pass": "test",
      "fs": "mail",
      "params": {
        "From": "alice@example.com",
        "To": "bob@example.com",
        "Subject": "New File",
        "Message": "A new file has been uploaded: %s",
        "Host": "smtp.example.com",
        "Port": "465",
        "Username": "smtpuser",
        "Password": "smtppassword"
      }
    }
  ]
}

Documentation

Overview

Package mail provides a mail access layer

Index

Constants

This section is empty.

Variables

View Source
var ErrFileTooLarge = errors.New("file too large")

ErrFileTooLarge is returned when an uploaded file exceeds the MaxSize limit

View Source
var ErrInvalidParameter = errors.New("invalid parameter")

ErrInvalidParameter is returned when a parameter is invalid

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when something is not found

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented is returned when something is not implemented

Functions

func LoadFs

func LoadFs(access *confpar.Access) (afero.Fs, error)

LoadFs loads a file system from an access description

Types

type File

type File struct {
	Path    string
	Content []byte
	Fs      *Fs
	At      int64
	// contains filtered or unexported fields
}

File is the afero.File implementation

func (*File) Close

func (f *File) Close() error

Close closes the file transfer and does the mail sending

func (*File) Name

func (f *File) Name() string

Name of the file

func (*File) Read

func (f *File) Read(b []byte) (int, error)

Read stores the received file content into the local buffer

func (*File) ReadAt

func (f *File) ReadAt(_ []byte, _ int64) (int, error)

ReadAt is not implemented

func (*File) Readdir

func (f *File) Readdir(_ int) ([]os.FileInfo, error)

Readdir is not implemented

func (*File) Readdirnames

func (f *File) Readdirnames(_ int) ([]string, error)

Readdirnames is not implemented

func (*File) Seek

func (f *File) Seek(_ int64, _ int) (int64, error)

Seek is not implemented

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat is not implemented

func (*File) Sync

func (f *File) Sync() error

Sync is not implemented

func (*File) Truncate

func (f *File) Truncate(_ int64) error

Truncate is not implemented

func (*File) Write

func (f *File) Write(b []byte) (int, error)

Write buffers the content, refusing it once the size limit is exceeded

func (*File) WriteAt

func (f *File) WriteAt(b []byte, off int64) (int, error)

WriteAt is not implemented

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

WriteString is not implemented

type Fs

type Fs struct {
	Dialer  mail.Dialer
	From    string
	To      string
	Subject string
	Message string
	MaxSize int64
}

Fs is a write-only afero.Fs implementation using mail as backend

func (*Fs) Chmod

func (m *Fs) Chmod(name string, mode os.FileMode) error

Chmod is not implemented

func (*Fs) Chown added in v0.9.0

func (m *Fs) Chown(string, int, int) error

Chown is not implemented

func (*Fs) Chtimes

func (m *Fs) Chtimes(name string, atime, mtime time.Time) error

Chtimes is not implemented

func (*Fs) Create

func (m *Fs) Create(name string) (afero.File, error)

Create creates a file buffer

func (*Fs) LstatIfPossible

func (m *Fs) LstatIfPossible(name string) (os.FileInfo, bool, error)

LstatIfPossible is not implemented

func (*Fs) Mkdir

func (m *Fs) Mkdir(name string, mode os.FileMode) error

Mkdir is not implemented

func (*Fs) MkdirAll

func (m *Fs) MkdirAll(name string, mode os.FileMode) error

MkdirAll is not implemented

func (*Fs) Name

func (m *Fs) Name() string

Name of the filesystem

func (*Fs) Open

func (m *Fs) Open(name string) (afero.File, error)

Open opens a file buffer

func (*Fs) OpenFile

func (m *Fs) OpenFile(name string, flag int, mode os.FileMode) (afero.File, error)

OpenFile opens a file buffer

func (*Fs) Remove

func (m *Fs) Remove(name string) error

Remove is not implemented

func (*Fs) RemoveAll

func (m *Fs) RemoveAll(name string) error

RemoveAll is not implemented

func (*Fs) Rename

func (m *Fs) Rename(name string, newname string) error

Rename is not implemented

func (*Fs) Stat

func (m *Fs) Stat(name string) (os.FileInfo, error)

Stat is not implemented

Jump to

Keyboard shortcuts

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