Many server software applications, like WordPress and Nextcloud can send alerts and notifications to the system admin and to users. Email is the most universal method for sending messages, but you have to run an email server (SMTP server) on the host. Processing incoming email messages is really resource consuming, but for alerts and notification messages the host only needs to send messages, not receive them. Here is a guide for setting up exim4 email server in send-only mode on Debian 10 Linux. Configuration of exim4 on Ubuntu is similar.
Depending on how your Debian system was set up, an email server like exim, Postfix or Qmail may already be installed on your host. You can test if you already have exim4 on your system:
systemctl status exim4
If the response is active (running), you can continue to configuration. Otherwise, install exim4:
apt-get install exim4
Configuring exim4 as a send-only email server
On Debian, exim4 comes with a configuration tool that is started like this:
The first question wants to know the type of email server you would like to have. Choose (don’t worry because later, mail receive will be prevented):
Internet site; mail is sent and received directly
Next, you must enter a valid domain name. If you are configuring, for instance, a laptop it probably doesn’t have a top level domain name. Enter a domain name you have.
In this step, you can prevent exim4 from receiving any mail. Entering the localhost address tells the email server not to listen to incoming messages.
You can accept the suggested names: your hostname and localhost in this step. In any case, the server won’t be receiving messages.
This mail configuration won’t relay messages, so you can leave the relay field blank.
Assuming the computer where you are installing the mail server has broadband connection, choose No.
This mail server won’t receive messages, but let the configuration choose the default option for mailbox format which is mbox.
Root and Postmaster mail recipient: enter an email address that you use regularly. These messages for the root are generated by the operating system, and include alerts and notifications.
The next step is to test if the mail server can send messages.
Testing and troubleshooting
A quick test for the email server can be achieved by sending a message with sendmail:
your test message is here
[Hit key combination ctrl d when you are ready to send the message]
If you don’t receive the test message to your inbox, view the log file:
Any error messages referring to domain names may indicate that the receiving email server wasn’t happy with your host’s domain name. Check the content of the following file:
The line should contain a valid domain name that DNS servers recognize.
The configuration file for exim4 is located here if you want to modify it manually:
NOTE: if you manually edit the configuration or mailname file, restart exim4 after saving the new configuration.
A configuration guide for Ubuntu (only minor differences) can be viewed here.