mailcrier

module
v0.1.0-rc6 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: BSD-3-Clause

README

Mailcrier

Started as a fork of github.com/iggy/slendmail.

A sendmail replacement for machines that send no email: cron, at, sudo, mdadm, smartd, fail2ban and every other tool that pipes a message into /usr/sbin/sendmail get it delivered to Telegram, Discord, Slack, ntfy, an HTTP webhook, a service of the shoutrrr library or a program of their own instead.

  • Accepts the command lines of the usual callers (-t, -i, -f, -F, -oi, -bi, -q and the rest) and reads MIME messages: encoded words, quoted-printable, base64, any charset, HTML parts and attachments.
  • Sends to all configured targets at the same time, each in the markup of its service with everything from the message escaped, cut to the length the service accepts, with the attachments it can take.
  • Keeps a message in a spool until every target has it: a service that is down gets it on a later queue run.
  • One static binary, installed setgid so that the jobs of any user can send while only root reads the tokens; logs to syslog.

Quick start

Mail of the host to a Telegram chat, on Debian or Ubuntu with the package of a release; rpm and apk differ in the package of steps 1 and 2, see Installation. Every step runs as root.

  1. Set the version of the newest release on https://github.com/6RUN0/mailcrier/releases and download its package:

    VERSION=0.1.0-rc5
    curl -fLO "https://github.com/6RUN0/mailcrier/releases/download/v$VERSION/mailcrier_${VERSION}_linux_amd64.deb"
    
  2. Install it; this replaces the MTA of the host:

    apt install "./mailcrier_${VERSION}_linux_amd64.deb"
    
  3. Put the token of your bot into a file only root and the group mailcrier read; how to create a bot and find the id of its chat is under Telegram:

    install -m 0640 -o root -g mailcrier /dev/null /etc/mailcrier.d/telegram.token
    printf '%s\n' '123456:ABC-your-token' > /etc/mailcrier.d/telegram.token
    
  4. Append the target to /etc/mailcrier.conf, with the id of your chat:

    [target.ops-telegram]
    type = "telegram"
    token_file = "/etc/mailcrier.d/telegram.token"
    chat_id = -1001234567890
    
  5. Check the file. The expected output is one line on stderr, exit status 0:

    mailcrier --check-config
    
    /etc/mailcrier.conf: 0 errors, 0 warnings
    

    An error names the line to fix, see Checking the configuration.

  6. Send a test message through the target. The expected output is one line on stdout, exit status 0, and the message in the chat:

    mailcrier --probe
    
    target=ops-telegram class=ok
    

    class=perm status=400 with chat not found means a wrong chat_id or a bot that is not in the chat.

  7. Send a mail the way cron does and read its records in the log:

    printf 'Subject: test\n\nhello\n' | sendmail root
    journalctl -t mailcrier --since -5min
    

    The records message received and target delivered with target=ops-telegram show the delivery; without journald they are in /var/log/mail.log (Debian, Ubuntu) or /var/log/maillog (RHEL, Rocky), see Logging.

Until step 4 every message is held in the spool with exit status 78; the first queue run after the file loads delivers them, see Spool and queue.

Documentation

Page What it answers
Installation packages, what they change on the host, upgrade, removal, build
Configuration the file, its strict check, terms, examples, [general], [strings], the table of target keys
Targets the destinations, one page per type: Telegram, Discord, Slack, ntfy, HTTP and Mattermost, exec hooks, shoutrrr
Long messages how a text over the limit is cut, what goes along as a file
Templates your own text per target: data, functions, failures
Routes and suppression which target gets which message, dropping noise, direct chats
Spool and queue retries, held and failed messages, limits, mailq
Checking the configuration --check-config and --probe
Logging where the records go, their fields, masked secrets
Privileges the setgid install and what an elevated call may do
Containers running without the setgid bit, memory
Command line sendmail flags, recipients, message parsing, exit statuses
SELinux the module of the rpm package
mailcrier(8) the manual page, also installed with the packages

Russian: README.ru.md.

Directories

Path Synopsis
cmd
mailcrier command
Command mailcrier is a sendmail replacement that delivers the mail of cron, at and other system tools to chat and webhook services.
Command mailcrier is a sendmail replacement that delivers the mail of cron, at and other system tools to chat and webhook services.
internal
app
Package app wires configuration, message, targets and delivery into one sendmail invocation.
Package app wires configuration, message, targets and delivery into one sendmail invocation.
backend
Package backend holds the types shared by every delivery target: the Sender interface, target capabilities, the rendered payload and the classified delivery error.
Package backend holds the types shared by every delivery target: the Sender interface, target capabilities, the rendered payload and the classified delivery error.
backend/discord
Package discord implements the discord target type: one execution of a channel webhook per message, with the attachments as files.
Package discord implements the discord target type: one execution of a channel webhook per message, with the attachments as files.
backend/hook
Package hook implements the exec target type: one run of a program per message, with the message on its stdin and the envelope in its environment.
Package hook implements the exec target type: one run of a program per message, with the message on its stdin and the envelope in its environment.
backend/ntfy
Package ntfy implements the ntfy target type: a JSON publish for the text and one more message per attachment, which ntfy allows one of.
Package ntfy implements the ntfy target type: a JSON publish for the text and one more message per attachment, which ntfy allows one of.
backend/shoutrrr
Package shoutrrr implements the shoutrrr target type: one send per message through a service of github.com/nicholas-fedor/shoutrrr, chosen by the scheme of the URL.
Package shoutrrr implements the shoutrrr target type: one send per message through a service of github.com/nicholas-fedor/shoutrrr, chosen by the scheme of the URL.
backend/slack
Package slack implements the slack target type through the Slack Web API: chat.postMessage for the text and the external upload methods for the attachments, which land in the thread of the message.
Package slack implements the slack target type through the Slack Web API: chat.postMessage for the text and the external upload methods for the attachments, which land in the thread of the message.
backend/telegram
Package telegram implements the telegram target type: the Bot API methods sendMessage for the text and sendDocument for each attachment, the first one with the text as caption when it is short enough.
Package telegram implements the telegram target type: the Bot API methods sendMessage for the text and sendDocument for each attachment, the first one with the text as caption when it is short enough.
backend/webhook
Package webhook implements the http target type: one request per message, POST unless configured otherwise, with the JSON document its template renders, or without a body for GET.
Package webhook implements the http target type: one request per message, POST unless configured otherwise, with the JSON document its template renders, or without a body for GET.
config
Package config loads and validates the mailcrier TOML configuration.
Package config loads and validates the mailcrier TOML configuration.
delivery
Package delivery renders a message for every target, sends it to all of them at once and turns the per-target outcomes into the process exit status.
Package delivery renders a message for every target, sends it to all of them at once and turns the per-target outcomes into the process exit status.
golden
Package golden compares test output with golden files in txtar format: one file per fixture, one section per output.
Package golden compares test output with golden files in txtar format: one file per fixture, one section per output.
message
Package message reads the mail a caller pipes into sendmail and exposes the parts a notification needs: decoded headers, the text of the body in UTF-8 and the attachments.
Package message reads the mail a caller pipes into sendmail and exposes the parts a notification needs: decoded headers, the text of the body in UTF-8 and the attachments.
redact
Package redact replaces registered secrets with a mask in everything the process logs.
Package redact replaces registered secrets with a mask in everything the process logs.
render
Package render turns a message into the text of one target with Go templates and fits that text into the target's length limit.
Package render turns a message into the text of one target with Go templates and fits that text into the target's length limit.
route
Package route selects the targets of a message and decides which messages are suppressed.
Package route selects the targets of a message and decides which messages are suppressed.
sendmail
Package sendmail parses a sendmail command line: flags in getopt style, the mode selected by argv[0], and the recipients.
Package sendmail parses a sendmail command line: flags in getopt style, the mode selected by argv[0], and the recipients.
spool
Package spool keeps messages on disk until every target has them.
Package spool keeps messages on disk until every target has them.
text
Package text escapes, measures and truncates text for the markup of each target.
Package text escapes, measures and truncates text for the markup of each target.
scripts
check-commits command
Command check-commits fails when a commit in REV..HEAD does not follow Conventional Commits: the changelog is generated from commit subjects, and a malformed subject drops the change from it.
Command check-commits fails when a commit in REV..HEAD does not follow Conventional Commits: the changelog is generated from commit subjects, and a malformed subject drops the change from it.
check-mutants command
Command check-mutants compares the mutants that survived a run of gremlins with a list of accepted ones, so that a new surviving mutant fails the run and an accepted one that a test now kills is dropped from the list.
Command check-mutants compares the mutants that survived a run of gremlins with a list of accepted ones, so that a new surviving mutant fails the run and an accepted one that a test now kills is dropped from the list.
check-refs command
Command check-refs fails when commit messages, code comments or documentation changed since a base revision refer to plan stages or to review and decision IDs.
Command check-refs fails when commit messages, code comments or documentation changed since a base revision refer to plan stages or to review and decision IDs.
check-release command
Command check-release fails unless the CI of a commit passed: a release is built from a tag, and the tag must point at a commit whose push run of the CI workflow on the development branch finished with every required job successful.
Command check-release fails unless the CI of a commit passed: a release is built from a tag, and the tag must point at a commit whose push run of the CI workflow on the development branch finished with every required job successful.

Jump to

Keyboard shortcuts

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