The war against Spam emails is still ongoing and lots of ways to deal with mails got and get developed.
Today mail servers have TLS certificates and authentications so sending out simple emails will probably get stuck in a Spam filters. Setting up mail is therefore not easy and full of options.
There are different protocols
Simple Mail Transfer Protocol (SMTP) for sending email (delivery between email servers)
Internet Message Access Protocol (IMAP) for receiving email (download/retrieval from the email server to the client) port: 143 or for SSL 993
POP3 got replaced by IMAP
Making use of a mail server as smtp.gmail.com put some dependencies as how to authenticate.
If mails are sent among a small network or even inside a single computer then Spam should not be an issue.
There are many mail programs that do some parts involved in sending and receiving emails. It is very complex to get an overview.
A good start is using the collection of command line tools from mailutils https://mailutils.org/
The mailutils collection does not include a MTA therefore an MTA needs to be installed to be complete.
Mail User Agent (MUA) are email clients and can be considered the front end of the mail system that makes to link to a user. It uses IMAP to communicate to MDA. Programs are thunderbird, mail from mailutils, mutt, gmail, ...
Mail Delivery Agent (MDA) receives emails from MTA's and stores it in a mailbox. It uses IMAP to communicate to the MUA. Programs are dovecot
postfix can also act as an MDA
It is not used for sending
It separates mail for the different users and mailboxes
A IMAP server must be running to be available when a MUA wants access to the mails. The daemon imap4d comes with mailutils see man imap4d.
For gentoo the useflags server tcpd and ldap must be set to get this imap4d server. /etc/init.d/imap4d start and rc-update add imap4d default
It can be configured in /etc/mailutils.conf
or better as include file in /etc/mailutils.d/
Mail Transfer (or Transport) Agent (MTA) are mail or smtp servers, that send out the emails to MTA's and receive emails from other MTA's using SMTP. Finally they pass the emails to MDA's. Programs are nullmailer, postfix or ssmtp
Just one MTA can be installed at a time. In gentoo when emerging postfix then the other ones as ssmtp or nullmailer will be un-merged
The nullmailer does something it does not do null. It is targeted to be easy and not having a full set of features. An application is sending alert messages from a machine. See https://wiki.archlinux.org/title/Nullmailer
/etc/nullmailer/remotes
can have everything needed to pass the emails to an external smtp server
smtp.example.com smtp --port=587 --auth-login --user=username@example.com --pass=password
nullmailer wants to know a bit more to work:
/etc/nullmailer/defaultdomain
used when no domain is specified in the destination email address, so add
gmail.com
/etc/nullmaler/me
<hostname>
of the local machine so add
<name of your machine>
/etc/nullmailer/pausetime to wait 1h before instead of 60s
3600
/etc/nullmailer/sendtimeout 3 min to try sending before giving up instead 1h
180
Since it is a server a service must be started /etc/init.d/nullmailer start and rc-update add nullmailer default
using sendmail from nullmailer mails can be sent as:
echo "Subject: sendmail test" | sendmail -v <recipient_address>
See https://mailutils.org/ and for a tutorial https://www.baeldung.com/linux/mail-system-mailutils https://wiki.gentoo.org/wiki/Postfix
The mails appear in maildir format where every message is a file and not the older mbox format where all messages are within one file.
For local users a Message Transfer Agent MTA as postfix must be installed
Edit /etc/mail/aliases
to suit your needs
# Custom alias for a local user
user_alias: <local_username>
Run /usr/bin/newaliases
In Gentoo there would be the mbox useflag for postfix to support the old mbox format
postfix check
Postfix is a server and needs to run rc-update add postfix default and rc-service postfix start
cat /var/log/mail.log to see if it is happy
To send mails:
For example as root send a mail to the <local_username>
mail <local_username>
enter text and Ctrl+D or
echo "Email body" | mail -s "Subject" <local_username>
The mail appears under ~/.maildir/new
or ~/mbox the older format and since it is a text file it can be read using cat
mail will show all the new mails and typing in the number will show a mail d <n>
will then delete it. q will quit.
e-mail addresses appear as <local_username>
@<machine_name>
.localdomain
mailutils info or mailutils --show-config-options
mail --config-lint
ssmtp allows to send automated mail and simplify applications dealing with configuring the mail.
For gentoo emerge ssmtp
After having it installed /etc/ssmtp/ssmtp.conf
needs to get the mail account settings. See https://wiki.archlinux.org/index.php/SSMTP