• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Debian

Simple Mailserver With Postfix, Dovecot, and Sieve on Debian 9

How VPS by How VPS
November 1, 2019
in Debian
0
0
SHARES
16
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Step 1: Install the necessary packages
  2. Step 2: Configure Dovecot and Postfix
  3. Step 3: Configure startup services
  4. Step 4: Testing the server and installing SSL
  5. Step 5 (optional): Sending/receiving mail as an unprivileged user
  6. Conclusion
  7. Want to contribute?


Note: This article assumes you’re running a fresh Debian 9 installation. Additionally, you must have root access to continue.

Step 1: Install the necessary packages

The first thing we need to do is install the packages for our mail server.

Execute the following as the root user.

apt-get install postfix dovecot-imapd dovecot-managesieved sendmail mailutils -y 

“-y” is a parameter for apt-get that allows us to accept the confirmations automatically.

When you’re greeted with the “Postfix Configuration” prompt, press the “Tab” key followed by the “Enter” key, and finally the “Enter” key once more to set Postfix as an Internet Site.

You will then need to enter your primary domain and then hit the “Enter” key.

Step 2: Configure Dovecot and Postfix

We need to first configure the email address used by the system to send rejection emails (e.g. bounced mail).

Open the file /etc/dovecot/conf.d/15-lda.conf in your favorite text editor, and find the line that looks like #postmaster_address =. Change it to this.

postmaster_address = postmaster@%d

Save and exit.

Next, open up /etc/postfix/main.cf. Scroll to the bottom, and append the following.

mailbox_command = /usr/lib/dovecot/deliver

Alternatively, you may enter this in your shell prompt.

echo 'mailbox_command = /usr/lib/dovecot/deliver' >> /etc/postfix/main.cf

Step 3: Configure startup services

Ideally, we’d like Postfix and Dovecot to start automatically.
Enter the following commands to tell SystemD to start them automatically.

systemctl enable postfix
systemctl enable dovecot

Now, let’s restart them to apply any configuration changes.

systemctl restart postfix
systemctl restart dovecot

Step 4: Testing the server and installing SSL

Let’s test what we’ve done so far to make sure everything is working properly.

echo "Testmail!" | mail -s "Testmail!" root@localhost

You should find a message similar to the following one in /var/log/mail.log.

install postfix/local[10309]: A0B361DDA2: to=<root@localhost>, relay=local, delay=0.02, delays=0.01/0/0/0.01, dsn=2.0.0, status=sent (delivered to command: /usr/lib/dovecot/deliver

Now that the basic service is working, there are two important things left to set up. The internet is not a friendly place, making encrypting as much as possible a necessity. In this case we will be using SSL/TLS. Ideally you would have a certificate from a trusted CA – such as Let’s Encrypt, for example, where you can get a certificate for free. For private usage, a self-signed certificate is fine, too.

You can generate a self-signed certificate with the following command.

mkdir /etc/dovecot/private
openssl req -newkey rsa:4096 -sha512 -x509 -days 365 -nodes -keyout /etc/dovecot/private/mykey.key -out /etc/dovecot/mycert.pem
chmod 600 /etc/dovecot/private/*

Append the following to /etc/postfix/main.cf.

smtpd_tls_cert_file = /etc/dovecot/private/mykey.pem
smtpd_tls_key_file = /etc/dovecot/private/mycert.pem
smtpd_use_tls = yes

Save, exit, and restart Postfix.

systemctl restart postfix

Now, open the ./etc/dovecot/conf.d/10-ssl.conf file.

Change the values in the configuration file.

ssl = yes
ssl_key = /etc/dovecot/private/mykey.pem
ssl_cert = /etc/dovecot/private/mycert.pem

Restart Dovecot.

systemctl restart dovecot

Test the SSL functionality.

openssl s_client -starttls smtp -crlf -connect domainYouEnteredEarlierInStep1:25

If the answer contains both certificate and connection information, then everything is working properly. The last step of this tutorial is the configuration of Sieve. Open /etc/dovecot/conf.d/15-lda.conf with your favorite text editor and edit the following line.

mail_plugins = $mail_plugins sieve

One last restart.

systemctl restart dovecot

Step 5 (optional): Sending/receiving mail as an unprivileged user

It’s considered unprofessional to send/receive emails with the root user. To resolve this, we’ll create an unprivileged user.

useradd -m myUser #-m is a parameter that forces the creation of the home directory
passwd myUser

Conclusion

Congratulations, you have setup a mailserver on your Vultr VPS.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

Setup Django on Debian 8

Next Post

How to Install Apache Cassandra 3.11.x on Debian 9

Next Post

How to Install Apache Cassandra 3.11.x on Debian 9

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet