How to Install Postfix Mail Server on a Debian Linux System

Install Postfix Mail Server on a Debian Linux System

Let’s see the installation and configuration process for the Postfix mail server on a Debian Linux system.  

Step 1: Postfix Installation  

Step 1: Postfix Installation

Postfix is regularly used due to its ease of use, minimal settings, and extensive usage. On your Debian-based Linux system, run the following command to install Postfix:  

Internet Sitesudo apt install postfix  

Before installing Postfix, it would be best to uninstall Sendmail from your system if it is already installed.  

sudo apt remove sendmail  

Postfix will ask you a few questions throughout the installation process. In the package configuration, first, select the Internet site, and next, enter the domain name.  

Like other Linux applications, Postfix also saves its configuration in files, and this postfix configuration is found in the main.cf file. Always make a backup of the default main.cf file.   

Step 2: Configure Postfix SMTP Server  

To begin, open the main.cf file in the text editor and modify its contents. The file contains a lot of basic information, such as mydomain and myhostname – the SMTP server. To get the server to function, adjust the settings.  

vim /etc/postfix/main.cf  

Step 3: Verify Postfix Mail Server  

You can add your domain name and IP address to the host file, and also, you can send your first mail via the postfix server by using the below command.  

hostnamectl set-hostname mail.fatih.com  
echo "192.168.0.100 fatih.lab mail.fatih.lab" >> /etc/hosts  
reboot  

By using the following command, check the contents of the hostname file after rebooting the system.  

hostname && cat /etc/hostname && hostname -s  
# Output 
 mail.fatih.com 
 mail.fatih.com  
mail  

Next, verify your port number by using the below command:  

netstat –tlpn  

Now compose your first message and check the progress. Then, use the command to send your first mail:  

echo "my first mail content" | mail -s "Hello Postfix" root  

After completing this step, check the Maildir folder listed in the main.cf file. If everything is fine then the email you have sent will be here.  

cat /Maildir/new/[Press Tab]  

Install and Configure Dovecot  

In this process, we’ll use Dovecot IMAP as our mail delivery agent to send emails to a local recipient’s mailboxes. IMAP is a protocol that operates on ports 143 and 993 (SSL), and with POP3, this is not the case. Users cannot set up several directories on the server.  

Run the following command to install the Dovecot core server and Dovecot IMAP package on Debian.  

sudo apt install dovecot-core dovecot-imapd  

After the Dovecot installation, first, create a connection between your Maildir folder and Dovecot. Then, locate the following lines in /etc/dovecot/conf.d/10-auth.conf and modify them   

disable_plaintext_auth = no  
auth_mechanisms = plain login  

To store emails in the Maildir location, open the/etc/dovecot/conf.d/10-mail.conf file and add the following line.  

mail_location = maildir:~/Maildir  

The final file to modify is /etc/dovecot/conf.d/10-master.conf. Search for the Postfix smtp-auth block and change the following:  

# Postfix smtp-auth  
unix_listener /var/spool/postfix/private/auth
 {   
mode = 0666   
user = postfix    
group = postfix  
}  

Dovecot’s default port is 143. Restart the dovecot service and check the port number:  

netstat –tlpn  

To send an email, create a new user and connect to port 25 with the below command:  

adduser test  

Connect to port 25 using nc command:  

nc localhost 25  

The command structure you need to edit the email content:  

mail from: root  
rcpt to: usertest  
data  
subject: subjecttest  
my mail content  
 quit  

Finally, ensure the mail is sent successfully, and this configuration process should deliver the mail to the Maildir folder. Verify it by using the following command:  

cat /home/testuser/Maildir/new/[Press Tab] 

To get more updates you can follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox
Loading

Written by actsupp-r0cks