Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Install mail server on Ubuntu or Debian

Rumi, September 12, 2023

Disclaimer:
This howto is tested on Ubuntu 16, 18, 20 and Debian 10, 11 edition.

Installing and configuring  postfix

Step 1 » Assign static IP and hostname and add a host entry for the host name .

Assign hostname in /etc/hostname

mail.tweenpath.net

Add a host entry in /etc/hosts

192.168.1.10 mail.tweenpath.net

Step 2 » Update the repositories.

tweenpath@mail:~$ sudo apt-get update

Step 3 » Install postfix and dependencies . Press enter for all prompted questions during installation. we will do that in the next step.

tweenpath@mail:~$ sudo apt-get install postfix

Step 4 » After installation issue the below command to configure postfix.

tweenpath@mail:~$ sudo dpkg-reconfigure postfix

Now you will be prompted for set of details . choose the following values and replace tweenpath.net with your domain name.

1. Internet Site
2. tweenpath.net
3. tweenpath
4. tweenpath.net, localhost.localdomain, localhost
5. No
6. 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/24
7. 0
8. +
9. all

Step 5 » Now configure Postfix for SMTP-AUTH using Dovecot SASL by adding the below lines to postfix config file /etc/postfix/main.cf .

home_mailbox = Maildir/
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes

Step 6 » Now generate a digital certificate for tls. Issue the commands one by one and provide details as per your domain.

tweenpath@mail:~$ openssl genrsa -des3 -out server.key 2048
tweenpath@mail:~$ openssl rsa -in server.key -out server.key.insecure
tweenpath@mail:~$ mv server.key server.key.secure
tweenpath@mail:~$ mv server.key.insecure server.key
tweenpath@mail:~$ openssl req -new -key server.key -out server.csr
tweenpath@mail:~$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
tweenpath@mail:~$ sudo cp server.crt /etc/ssl/certs
tweenpath@mail:~$ sudo cp server.key /etc/ssl/private

Step 7 » Now configure certificate path

tweenpath@mail:~$ sudo postconf -e 'smtpd_tls_key_file = /etc/ssl/private/server.key'
tweenpath@mail:~$ sudo postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/server.crt'

Step 8 » Open /etc/postfix/master.cf file and uncomment below lines to enable smtps ( 465 ) and submission ( 587 )

submission inet n - - - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
smtps inet n - n - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING

Step 9 » Now install Dovecot SASL by typing the below command.

tweenpath@mail:~$ sudo apt-get install dovecot-common

Issue the following values for the prompts during installation.

1. yes
2. mail.tweenpath.net

Step 10 » Make changes to the files as follows.

Open /etc/dovecot/conf.d/10-master.conf file and find # Postfix smtp-auth line ( line no:95 ) and add the below lines .

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

Open /etc/dovecot/conf.d/10-auth.conf file and find (line no:100)

auth_mechanisms = plain and replace auth_mechanisms = plain login

Step 11 » Restart postfix and dovecot services

tweenpath@mail:~$ sudo service postfix restart
tweenpath@mail:~$ sudo service dovecot restart

Step 12 » Now test SMTP-AUTH and smtp/pop3 port access .

Type the below command and should get below response.

tweenpath@mail:~$ telnet mail.tweenpath.net smtp
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.tweenpatha.net ESMTP Postfix (Ubuntu)

Now type ehlo mail.tweenpath.net and should get below response , please make sure you get those bolded lines .

ehlo mail.tweenpath.net
250-mail.tweenpath.net
--------
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
---------
250 DSN and try the same with port 587 (telnet mail.tweenpath.net 587).
Postfix configuration is over, continue for dovecot installation.
» Installing and configuring dovecot

Step 12 » Install dovecot using the below command

tweenpath@mail:~$ sudo apt-get install dovecot-imapd dovecot-pop3d

Step 13 » Now configure mailbox. Open /etc/dovecot/conf.d/10-mail.conf file and find (Line no:30 )

mail_location = mbox:~/mail:INBOX=/var/mail/%uReplace with
mail_location = maildir:~/Maildir

Step 14 » Now change pop3_uidl_format . Open /etc/dovecot/conf.d/20-pop3.conf file and find and uncomment the below line ( Line no : 50 )

pop3_uidl_format = %08Xu%08Xv

Step 15 » Now enable SSL . Open /etc/dovecot/conf.d/10-ssl.conf file and find and uncomment the below line ( Line no : 6 )

ssl = yes

Step 16 »Restart dovecot service.

tweenpath@mail:~$ sudo service dovecot restart

Step 17 » Now test pop3 and imap port access using the telnet command.

tweenpath@mail:~$ telnet mail.tweenpath.net 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot (Ubuntu) ready. Repeat the same for 995,993,143 ports.

OR check for listening ports using netstat command .

tweenpath@mail:~$ netstat -nl4 you should get the result like below.

Step 18 » Create some users and check using mail clients like thunderbird or outlook

tweenpath@mail:~$ sudo useradd -m bobby -s /sbin/nologin
tweenpath@mail:~$ sudo passwd bobby

Now mail server is ready, you can send and receive mail using the server. Continue for squirrelmail ..

» Installing and configuring squirrelmail

Step 19 » Install squirrelmail using the below command. This will install apache and PHP packages.

tweenpath@mail:~$ sudo apt-get install squirrelmail

Step 20 » Configure squirrelmail

tweenpath@mail:~$ sudo squirrelmail-configureEverything is pre-configured , we just need to change Organization name .
» Press 1 (Organization Preferences) » again press 1 (Organization Name) » Organization Name » Press S » Press Q to quit

Step 19 » Now configure apache to enable squirrelmail .

tweenpath@mail:~$ sudo cp /etc/squirrelmail/apache.conf /etc/apache2/sites-available/squirrelmail.conf
tweenpath@mail:~$ sudo a2ensite squirrelmail

Step 20 » Restart Apache service

tweenpath@mail:~$ sudo service apache2 restart

Step 21 » Now open http://serverIP/squirrelmail in your browser and login using username (bobby) . you can send and receive mail using squirrelmail.

Ref:
https://www.krizna.com/ubuntu/setup-mail-server-ubuntu-14-04/amp/
https://help.ubuntu.com/community/PostfixAmavisNew

Administrations Collected Articles Configurations (Linux) DebianDovecotMail ServerPostfixSquirrelmailUbuntu

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

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

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads