Atlantic.Net Blog

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

Hitesh Jethva
by Atlantic.Net (273 posts) under Tutorials, VPS Hosting
0 Comments

A mail server is very useful when you own a website or web application and want to send transactional emails to users. Postfix is a free and open-source Mail Transfer Agent used to send and receive emails. Postfix is absolutely free, so you don’t need to rely on third-party service providers like Sendgrid or Pepipost. You can easily install and configure Postfix to send emails through your local application.

In this post, we will show you how to install and configure Postfix as a Send-Only SMTP server on Ubuntu 20.04.

Prerequisites

  • An Ubuntu 20.04 server on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 20.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Setup Hostname

Before starting, you will need to set up a fully qualified hostname on your server. You can set up it with the following command:

hostnamectl set-hostname email.linuxbuz.com

Next, edit /etc/hosts file and add the following line:

nano /etc/hosts

Add the following line:

your-server-ip email.linuxbuz.com

Save and close the file when you are finished.

Step 3 – Install Postfix

The simple and easiest way to install Postfix is to install mailutils package to your system.

You can install the mailutils package using the following command:

apt-get install mailutils -y

During the installation, you will be asked to select the type of mail configuration as shown below:
Postfix select internet site
Select Internet Site and hit Enter. You will be asked to provide your mail name as shown below:
Postfix select domain name
Provide your domain name and hit Enter to finish the installation.

Next, check the status of Postfix using the following command:

systemctl status postfix

Step 4 – Configure Postfix as a Send-Only SMTP Server

Next, you will need to configure Postfix to send an email from the local host. You can configure it by editing the Postfix main configuration file:

nano /etc/postfix/main.cf

Change the following line:

inet_interfaces = loopback-only

Save and close the file, then set the hostname directly in the Postfix configuration file using the following command:

postconf -e "myhostname = email.linuxbuz.com"

Next, verify your configured domain name using the following command:

postconf mydomain

You should get the following output:

mydomain = email.linuxbuz.com

You will also need to verify the default domain name that is appended to sender and recipient addresses.

postconf myorigin

Sample output:

myorigin = /etc/mailname

Next, display the content of the above file using the following command:

cat /etc/mailname

You should see your domain in the following output:

email.linuxbuz.com

Finally, restart the Postfix service to apply the changes:

systemctl restart postfix

You can also check the status of Postfix with the following command:

systemctl status postfix

Sample output:

‚óŹ postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
     Active: active (exited) since Sun 2021-08-15 12:52:44 UTC; 9s ago
    Process: 4230 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 4230 (code=exited, status=0/SUCCESS)

Aug 15 12:52:44 ubuntu2004 systemd[1]: Starting Postfix Mail Transport Agent...
Aug 15 12:52:44 ubuntu2004 systemd[1]: Finished Postfix Mail Transport Agent.

Step 5 – Verify Postfix Server

At this point, Postfix is installed and configured as a send-only SMTP server. Now, it’s time to send emails to an external email account.

You can use the following command to send a simple email to the external email address:

echo "This is the body of the email" | mail -s "This is the subject line" [email protected]

You should now see the message in your Inbox or Spam folder.

Step 6 – Forward System Mail

It is a good idea to forward all system mail to your external email address. In this section, we will set up email forwarding for the root user.

Edit the /etc/aliases file:

nano /etc/aliases

Find the following line:

postmaster:    root

And replace it with the following line:

root:    [email protected]

Save and close the file, then run the following command to apply the changes:

newaliases

Now, verify email forwarding by sending an email to the root user:

echo "This new email" | mail -s "This is new email" root

If everything is fine, you should receive an email at your external email address.

Conclusion

Congratulations! You have successfully set up a Postfix as a send-only SMTP server. You can now use this setup with your application to notify your users via email. Give it a try on your VPS from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources