How to install smtp mail server in ubuntu

Installing an SMTP mail server on Ubuntu is a relatively straightforward process. Here's a step-by-step guide to help you get started:

Prerequisites:

  1. Ubuntu 18.04 or later (other versions may work, but this guide is specifically for 18.04 and later)
  2. A domain name (optional, but recommended for a fully functional mail server)
  3. A static IP address (optional, but recommended for a fully functional mail server)

Step 1: Install Postfix

Postfix is a popular and widely-used SMTP mail server. You can install it using the following command:

sudo apt-get update
sudo apt-get install postfix

Step 2: Configure Postfix

Postfix comes with a default configuration file, but you'll need to make some changes to get it working. You can do this by editing the /etc/postfix/main.cf file:

sudo nano /etc/postfix/main.cf

Add the following lines to the end of the file:

mydestination = yourdomain.com
myhostname = yourdomain.com
myorigin = $myhostname

Replace yourdomain.com with your actual domain name.

Step 3: Set up DNS

To send and receive emails, you'll need to set up DNS records for your domain. You'll need to create the following records:

  1. A record: yourdomain.com -> your-IP-address
  2. MX record: yourdomain.com -> your-IP-address (with a priority of 0)

You can do this by editing your DNS provider's settings or by using a DNS management tool like bind9.

Step 4: Configure Postfix to use your DNS

Edit the /etc/postfix/main.cf file again:

sudo nano /etc/postfix/main.cf

Add the following lines to the end of the file:

mynetworks = 127.0.0.0/8 [::1]/128
mydestination = yourdomain.com
myhostname = yourdomain.com
myorigin = $myhostname

Step 5: Restart Postfix

Restart the Postfix service to apply the changes:

sudo service postfix restart

Step 6: Test your mail server

You can test your mail server using the following command:

sudo telnet your-IP-address 25

This should connect you to the Postfix SMTP server. You can then send a test email using the mail command:

sudo mail -s "Test email" [email protected]

Replace your-email-address with the email address you want to send the test email from.

Step 7: Configure your email client

Finally, you'll need to configure your email client (e.g., Thunderbird, Outlook) to use your new mail server. You can do this by setting the SMTP server to your-IP-address and the port to 25.

That's it! You should now have a functional SMTP mail server up and running on your Ubuntu machine.