How to Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04

How to Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 20.04

For sending and receiving emails, Postfix is utilised. In many cases, the server’s sole purpose is to send mail. To transmit notifications from apps, for example in these situations, the Postfix option for transmitting messages only comes in handy.

Initial conditions

  • Ubuntu 20.04
  • Domain name
  • DNS A record containing your domain’s public IP address
  • TLS certificate for e-mail encryption

Installing Postfix

Installing the mailutils package, which includes Postfix and a few additional packages, is the simplest option.

sudo apt install mailutils

A window for setting Postfix will open during installation.

01..Figure

In our instance, an Internet site is the best alternative. Set the System mail name after you’ve selected it. It must be the same as your hostname and domain name.

02..Figure

Postfix Configuration

We only need to listen to the loopback interface to send emails from the current server. Change the “inet interfaces” parameter in the main.cf file to loopback-only.

sudo nano /etc/postfix/main.cf
inet_interfaces = loopback-only

Also, make the following changes to the mydestination parameter.

mydestination = localhost.$mydomain, localhost, $myhostname

Postfix should be restarted.

sudo systemctl restart postfix

For sending emails from the server, the present settings are sufficient. Let’s put it to the test.

Testing after the postfix

To see if Postfix will send an email, we’ll use the mail command.

echo "Fill in some text of the email here" | mail -s "Message subject" recipient's-email-address

Fill in the title and message text. Instead of the recipient’s email address, the email will be sent to the specified address.

If the email does not come, check the Spam folder. If it isn’t there, you’ll need to double-check your settings. A mismatch between the host name, server name, and your domain name could also cause issues.

Enable SMTP encryption

For security reasons, email encryption is critical. Unencrypted emails are also considered spam by some systems.

A valid certificate must be specified in the Postfix configuration to encrypt email.

sudo nano /etc/postfix/main.cf

In the smtpd tls cert file field, specify the path to the TLS domain certificate, the private key in the smtpd tls key file field, and yes in the smtp use tls field.

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/domain-name.pem
smtpd_tls_key_file=/etc/ssl/private/domain-private-key.pem
smtp_use_tls=yes

Posfix should be restarted.

sudo systemctl restart postfix

Setting up aliases

Internal messages for users must occasionally be redirected to the inbox. To reroute system messages, for example. This is accomplished through the use of aliases. Edit the following file to customise them:

sudo nano /etc/aliases

At the conclusion of the file, add a line. We’ll configure sending system messages to mail@domain.com in this example.

root: mail.@domain.com

Save and close the file. To make the modifications, type the following command:

sudo newaliases

Follow us TwitterFacebookLinkedIn

Open Source Listing

Previous Post
Next Post

Comments

How to Install and Configure Samba File Server on Ubuntu 20.04 - Open Source Listing

[…] the OS/2 operating systems for file and printer sharing, as well as other functions. It runs on a Unix system and allows Windows to share files and printers with the Unix host, as well as giving Unix users […]

Leave a Reply

Your email address will not be published. Required fields are marked *