Use external SMTP server for system mails on Linux

To use an external SMTP for all system e-mails, you have to install these:

Where msmtp-mta transform the external reference in the sendmail command usable by any application using sendmail. In this way you haven’t to install and configure Postfix since you’ll rely on an external SMTP service.

Create the config file for msmtp

This is an example based on the popular Gmail by Google:

Replace these with the real data from your e-mail account.

In this example, the realaccount@example.com in GMail is the user that created the Gmail app password. He has to have the senderaddress@example.com configured as sender address alias in GMail.

realaccount@example.com

senderaddress@example.com

configured as sender address alias in GMail

Add aliases

To match local users with sender address, create the aliases file:

If you’ve any process sending emails using a specific username, add to this list with the right email to use. Any occurrence of the original address will be translated to the right address.

First test

Type this to test the new configuration:

Additional step

If you need to use the mail command, install mailutils without installing postfix:

Then you can use something like:

echo -e “Print a variable here $MYVAR.\\n\\n– \\nSign here“ \| mail -s “Type your subject here“ $EMAIL

Here some variables are added as you can use them in a custom script.

Using msmtp command directly

If you already use the base mail command and you don’t want to replace it with mail, you can use this:

(echo -e “Subject: Type your subject here“; echo; echo -e “Print a variable here $MYVAR.\\n\\n– \\nSign here“) \| msmtp -a default $EMAIL

Done

Now any application using sendmail will actually use your external SMTP service. Use a mail server supporting TLS to avoid transmitting clear text filled with system information.

Tested on Ubuntu Linux 18

https://web.archive.org/web/20180725000000*/https://support.google.com/mail/answer/22370?hl=en

Proxied content from gemini://chirale.org/2018-07-25_4330.gmi (external content)

Gemini request details:

Original URL
gemini://chirale.org/2018-07-25_4330.gmi
Status code
Success
Meta
text/gemini; charset=utf-8
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.