sendmail

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

README

sendmail

Go Reference

Standalone drop-in replacement for sendmail with direct send

Features

  • Full sendmail replacement for direct mail without intermediate mail services
  • One standalone binary without dependencies
  • Optional SMTP and HTTP backends
  • Possible use as a golang package

Install

Download binaries from release page.

Or install from source:

go get -u github.com/n0madic/sendmail/cmd/sendmail

Help

Usage of sendmail:
  -f string
    	Set the envelope sender address.
  -http
    	Enable HTTP server mode.
  -httpBind string
    	TCP address to HTTP listen on. (default "localhost:8080")
  -httpToken string
    	Use authorization token to receive mail (Token: header).
  -i	When reading a message from standard input, don't treat a line with only a . character as the end of input.
  -s string
    	Specify subject on command line.
  -senderDomain value
    	Domain of the sender from which mail is allowed (otherwise all domains). Can be repeated many times.
  -smtp
    	Enable SMTP server mode.
  -smtpBind string
    	TCP or Unix address to SMTP listen on. (default "localhost:25")
  -t	Extract recipients from message headers. IGNORED (default true)
  -v	Enable verbose logging for debugging purposes.

Usage

Send email like sendmail:

$ cat mail.msg | sendmail user@example.com

Send email like mail/mailx:

$ echo TEST | sendmail -s "Test Subject" user@example.com

Send via smart host:

$ export SENDMAIL_SMART_HOST=mail.server.com
$ export SENDMAIL_SMART_LOGIN=user           # Optional
$ export SENDMAIL_SMART_PASSWORD=secret      # Optional
$ cat mail.msg | sendmail user@example.com

Use as SMTP service:

$ sendmail -smtp

$ telnet localhost 25
> HELO localhost
> MAIL FROM: sender@localhost
> RCPT TO: user@example.com
> DATA
...

Use as HTTP service:

$ sendmail -http

$ curl -X POST --data-binary @mail.msg localhost:8080

With authorization token:

$ sendmail -http -httpToken werf2t34cr243

$ curl -X POST -H 'Token: werf2t34cr243' --data-binary @mail.msg localhost:8080

Limit the sender's domain:

$ sendmail -http -smtp -senderDomain example1.com -senderDomain example2.com

Use as package

package main

import (
    "github.com/n0madic/sendmail"
    log "github.com/sirupsen/logrus"
)

func main() {
    envelope, err := sendmail.NewEnvelope(&sendmail.Config{
        Sender:     "sender@localhost",
        Recipients: []string{"user@example.com"},
        Subject:    "Test Subject",
        Body:       []byte("TEST"),
    })
    if err != nil {
        log.Fatal(err)
    }

    errs := envelope.Send()
    for result := range errs {
        switch {
        case result.Level > sendmail.WarnLevel:
            log.Info(result.Message)
        case result.Level == sendmail.WarnLevel:
            log.Warn(result.Error)
        case result.Level < sendmail.WarnLevel:
            log.Fatal(result.Error)
        }
    }

}

Documentation

Overview

Package sendmail is intended for direct sending of emails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressListToSlice

func AddressListToSlice(list []*mail.Address) (slice []string)

AddressListToSlice convert mail.Address list to slice of strings

func GetDomainFromAddress added in v0.2.0

func GetDomainFromAddress(address string) string

GetDomainFromAddress extract domain from email address

func GetDumbMessage

func GetDumbMessage(sender string, recipients []string, body []byte) (*mail.Message, error)

GetDumbMessage create simple mail.Message from raw data

Types

type Config

type Config struct {
	Sender     string
	Recipients []string
	Subject    string
	Body       []byte
	PortSMTP   string
}

Config of envelope

type Envelope

type Envelope struct {
	*mail.Message
	Recipients []string
	PortSMTP   string
}

Envelope of message

func NewEnvelope

func NewEnvelope(config *Config) (Envelope, error)

NewEnvelope return new message envelope

func (*Envelope) GenerateMessage

func (e *Envelope) GenerateMessage() ([]byte, error)

GenerateMessage create body from mail.Message

func (*Envelope) Send

func (e *Envelope) Send() <-chan Result

Send message. It returns channel for results of send. After the end of sending channel are closed.

func (*Envelope) SendLikeMTA

func (e *Envelope) SendLikeMTA() <-chan Result

SendLikeMTA message delivery directly, like Mail Transfer Agent.

func (*Envelope) SendSmarthost

func (e *Envelope) SendSmarthost(smarthost, login, password string) <-chan Result

SendSmarthost message delivery through an external mail server.

type Fields

type Fields map[string]interface{}

Fields type, used for expand information.

type Level

type Level uint32

Level type of result

const (
	// FatalLevel level.
	FatalLevel Level = iota
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the application.
	InfoLevel
)

type Result

type Result struct {
	Level   Level
	Error   error
	Message string
	Fields  Fields
}

Result of send

Directories

Path Synopsis
cmd
sendmail
Standalone drop-in replacement for sendmail with direct send
Standalone drop-in replacement for sendmail with direct send

Jump to

Keyboard shortcuts

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