There are several ways, actually.
The simplest approach is most likely the sendmail
command that ships with Postfix, since that does not require additional software:
from='me@example.org'
to='postmaster@foo.example.com'
subj='Foo'
msg='Your message.'
echo -e "Subject: ${subj}\n\n${msg}" | sendmail -f "$from" "$to"
Another option would be the mailx
commandline utility. However, you probably need to install that first (for Debian-based systems it's in the package bsd-mailx
):
from='me@example.org'
to='postmaster@foo.example.com'
subj='Foo'
msg='Your message.'
echo "$msg" | mailx -r "$from" -c '' -s "$subj" "$to"
Or you could install something like Mutt, which provides you with an ncurses-based interface. The program needs some configuration, though. Create a file .muttrc
with the following content in your userhome:
# ~/.muttrc
set mbox_type=maildir
set spoolfile="/var/mail/USERNAME"
set folder="~/Mail/"
Replace USERNAME
with your actual username on the system.
You can instruct the client to use a specific from address by adding this line:
set from=me@example.org
and/or make headers (including the From: header) editable by adding
set edit_hdrs=yes