From 3f68ace3f85691bfec609c917afd74760504e749 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 16 Feb 2024 21:28:21 +0100 Subject: [PATCH] refactor: kb article on the mail util --- knowledge base/mail.md | 63 ++++++++++++++++++++++++ knowledge base/send an email from cli.md | 28 ++--------- 2 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 knowledge base/mail.md diff --git a/knowledge base/mail.md b/knowledge base/mail.md new file mode 100644 index 0000000..fcbab9c --- /dev/null +++ b/knowledge base/mail.md @@ -0,0 +1,63 @@ +# Mail + +1. [TL;DR](#tldr) +1. [Further readings](#further-readings) + 1. [Sources](#sources) + +## TL;DR + +```sh +# Just test the presence for new emails. +# Exit status '0' means there are, '1' there is none. +mail -e + +# Read all unread emails at once. +cat '/var/mail/username' + +# Read automatically saved messages. +cat "$HOME/mbox" + +# Send emails. +mail -s 'Subject' 'recipient@mail.server' +echo '' | mail -a 'attachment.file' -s 'Subject' 'recipient@mail.server' + +# Send larger files. +cat 'file.txt' | mail -s 'Subject' 'recipient@mail.server' + +# Make "email-safe" the contents of a file before sending it. +uuencode 'file.txt' | mail -s 'Subject' 'recipient@mail.server' + +# Delete all emails at once. +echo -n > '/var/mail/username' +sudo rm '/var/mail/username' +``` + +| Command | Description | +| ------------------------------------------------------------- | ---------------------------------------------------- | +| `?` | View the help | +| `p`, `print`
`p 3`
`p 3 6`
`p 3-10`
`p *` | Print all messages in the list to the default output | +| `t`, `type` | Synonym for `p` | +| `mo`, `more`
`mo 3`
`mo 3 6`
`mo 3-10`
`mo *` | Print all messages in the list to the default pager | +| `n`, `next`
`n 3`
`n 3 6`
`n 3-10`
`n *` | Print the next message in the list | +| `d`, `delete`
`d 3`
`d 3 6`
`d 3-10`
`d *` | Mark all messages in the list as deleted | +| `q`, `quit` | Quit saving unresolved messages under `~/mbox` | +| `x`, `ex`, `exit` | Quit **without** making changes to the mailbox | + +## Further readings + +### Sources + +- [`man` page][man page] + + + + + + + + +[linux mail command examples]: https://www.binarytides.com/linux-mail-command-examples/ +[man page]: https://linux.die.net/man/1/mail +[uuencode]: https://linux.101hacks.com/unix/uuencode/ diff --git a/knowledge base/send an email from cli.md b/knowledge base/send an email from cli.md index b6a652b..b386fcc 100644 --- a/knowledge base/send an email from cli.md +++ b/knowledge base/send an email from cli.md @@ -1,32 +1,10 @@ # Send an email from CLI -## Table of contents - -1. [TL;DR](#tldr) -1. [Further readings](#further-readings) - -## TL;DR - -```sh -mail -s "Subject" recipient@mail.server -echo "" | mail -a attachment.file -s "Subject" recipient@mail.server - -# send larger files -cat file.txt | mail -s "Subject" recipient@mail.server - -# make "email-safe" the contents of a file -uuencode file.txt | mail -s "Subject" recipient@mail.server -``` - -## Further readings - -- [linux mail command examples] -- [uuencode] +For Unix-like systems, see [`mail`][mail]. - -[linux mail command examples]: https://www.binarytides.com/linux-mail-command-examples/ -[uuencode]: https://linux.101hacks.com/unix/uuencode/ + +[mail]: mail.md