Install
apt install sendmail
Modify /etc/mail/sendmail.mc
to configure your smarthost/SMTP server.
The following config must be placed directly before the MAILER_DEFINITIONS
section.
This will define your SMTP server and force all outbound mail to come from the specified domain.
define('SMART_HOST', 'smtp.example.com')dnl
FEATURE(always_add_domain)dnl
FEATURE(`masquerade_entire_domain')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(`allmasquerade')dnl
MASQUERADE_AS(`example.com.')dnl
MASQUERADE_DOMAIN(`example.com.')dnl
MASQUERADE_AS(example.com)dnl
Add your SMTP authentication info the /etc/mail/authinfo
using the following format
AuthInfo:smtp.yourisp.com "U:user" "P:password" "M:PLAIN"
Generate the authentication database using the previous file
makemap hash /etc/mail/authinfo < /etc/mail/authinfo
Use m4
to create the sendmail config from sendmail.mc
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Restart sendmail
systemctl restart sendmail
Test sendmail
echo "Test email body" | mail -s "Test Email Subject" your-email@example.com